【问题标题】:Docker file builds correctly but fails to runDocker 文件正确构建但无法运行
【发布时间】:2020-05-12 16:56:08
【问题描述】:

$ docker image build -t python-blog .

Step 1/5 : FROM ubuntu:16.04
 ---> 005d2078bdfa

Step 2/5 : RUN apt-get update -y &&     apt-get install -y python-pip python-dev
 ---> Using cache
 ---> 7c1fdabcc215

Step 3/5 : ADD . .
 ---> Using cache
 ---> 5e2784fac3bd

Step 4/5 : RUN pip install -r requirements.txt
 ---> Using cache
 ---> 7d038ff8d993

Step 5/5 : CMD ["/usr/bin/python3","run.py"]
 ---> Using cache
 ---> 24f691d13886

Successfully built 24f691d13886
Successfully tagged python-blog:latest

$ docker run -p 5000:5000 python-blog:latest

docker:来自守护进程的错误响应:OCI 运行时创建失败: container_linux.go:349:启动容器进程导致“exec: \"/usr/bin/python3\": stat /usr/bin/python3: 没有这样的文件或 目录”:未知。ERROr [0005] 错误等待容器:上下文 取消

Dockerfile

FROM ubuntu:16.04

RUN apt-get update -y && \
    apt-get install -y python-pip python-dev

ADD . .

RUN pip install -r requirements.txt

CMD ["/usr/bin/python3","run.py"]

【问题讨论】:

  • 你可能想安装 python3-pip 和 python3-dev 并使用 pip3。
  • 非常感谢,您的更改有效@hmm

标签: python-3.x docker flask dockerfile


【解决方案1】:

您的 Dockerfile 并没有专门安装 python3,ubuntu-16.04 默认选择 python (2.7.12-1ubuntu0~16.04.11),这就是它无法执行期望 /usr/bin/python3 的 CMD 指令的原因不存在。

如果你想用 python3 运行你的代码,你必须更新你的 Dockerfile 来专门安装 python3。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 2019-06-28
    • 2018-12-28
    • 1970-01-01
    相关资源
    最近更新 更多