【问题标题】:Successful built docker image does not run when environment was built from anaconda从 anaconda 构建环境时,成功构建的 docker 映像不会运行
【发布时间】:2019-07-04 04:00:21
【问题描述】:

我使用以下 Dockerfile 构建了一个 docker 映像:

FROM continuumio/miniconda3

ENTRYPOINT [ “/bin/bash”, “-c” ]

ADD angular_restplus.yaml angular_restplus.yaml

RUN ["conda", "env", "create", "-f", "angular_restplus.yaml"]

RUN ["/bin/bash", "-c", "source activate work"]

COPY json_to_db.py json_to_db.py

CMD ["gunicorn", "-b", "0.0.0.0:3000", "json_to_db:app"]

以及构建它的命令:

sudo docker build -t testimage:latest .

贯穿始终:

Step 5/7 : RUN ["/bin/bash", "-c", "source activate work"]
 ---> Running in 45c6492b1c67
Removing intermediate container 45c6492b1c67
 ---> 5b5604dc281d
Step 6/7 : COPY json_to_db.py json_to_db.py
 ---> e5d05858bed1
Step 7/7 : CMD ["gunicorn", "-b", "0.0.0.0:3000", "json_to_db:app"]
 ---> Running in 3ada6fd24d09
Removing intermediate container 3ada6fd24d09
 ---> 6ed934acb671
Successfully built 6ed934acb671
Successfully tagged testimage:latest

但是,当我现在尝试使用它时,它不起作用;我试过了:

sudo docker run --name testimage -d -p 8000:3000 --rm testimage:latest

打印出来效果不错

b963bdf97b01541ec93e1eb7

但是,我无法在浏览器中访问该服务并使用

sudo docker ps -a

仅显示从上方创建图像所需的中间容器。

当我尝试在没有 -d 标志的情况下运行它时,我得到了

gunicorn: 1: [: “/bin/bash”,: unexpected operator

这是否意味着我必须再次更改ENTRYPOINT?如果有,是什么?

【问题讨论】:

标签: docker anaconda dockerfile


【解决方案1】:

可以在以下post找到解决方案。我不得不使用

"/bin/bash", "-c"

部分自始至终。现在以下工作正常(同时使用@larsks'输入谁删除了他的答案):

FROM continuumio/miniconda3

COPY angular_restplus.yaml angular_restplus.yaml
SHELL ["/bin/bash", "-c"] 
RUN ["conda", "env", "create", "-f", "angular_restplus.yaml"]
COPY json_to_db.py json_to_db.py
CMD source activate work; gunicorn -b 0.0.0.0:3000 json_to_db:app

然后就可以跑了

docker build -t testimage:latest .

最后

docker run --name testimage -d -p 3000:3000 --rm testimage:latest

如果现在使用

docker ps -a

一个人会得到预期的结果:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
61df8ac0432c        testimage:latest    "/usr/bin/tini -- /b…"   16 seconds ago      Up 15 seconds       0.0.0.0:3000->3000/tcp   testimage

然后就可以访问服务了

http://localhost:3000/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-06
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2019-04-06
    相关资源
    最近更新 更多