运行瓶应用如何作为docker容器?

How run bottle application as docker-container?

我制作了 bottle-framework-application,它在本地主机上运行良好。我使用 virtualenv.

然后我构建 docker 容器。我的 Dockerfile:

FROM ubuntu
COPY . .
RUN /bin/bash -c "source venv/bin/activate"
ENTRYPOINT /bin/bash -c "python3 index.py"

双向处理没问题:

(venv) kalinin@md ~/python/bottler $ docker build -t bottler .
Sending build context to Docker daemon  26.07MB
Step 1/4 : FROM ubuntu
 ---> 7698f282e524
Step 2/4 : COPY . .
 ---> 9e182c969051
Step 3/4 : RUN /bin/bash -c "source venv/bin/activate"
 ---> Running in 2022e2fa7600
Removing intermediate container 2022e2fa7600
 ---> 16209d249539
Step 4/4 : ENTRYPOINT python3 index.py
 ---> Running in 84594de70d72
Removing intermediate container 84594de70d72
 ---> d5057555ab1a
Successfully built d5057555ab1a
Successfully tagged bottler:latest

构建后,我尝试 运行 容器:

docker run -i -t --rm -p 8000:8000 bottler

但得到以下错误信息:

/bin/bash: python3: command not found

请帮助我的 运行 申请。在 运行 之后我需要在浏览器中查看应用程序。

首先,我建议您使用 python 图片 https://hub.docker.com/_/python 之一,因为您使用的 ubuntu 图片可能没有 python pre-installed.

其次,我建议您将 ENTRYPOINT 定义为单个 command/executable - 在您的情况下 python

ENTRYPOINT ["python"]

然后在CMD定义中添加.py文件的路径

CMD ["index.py"]

您遇到的问题是,在 ubuntu 映像中,在 $PATH 中找不到 python 可执行文件,因为它不是 pre-installed。您应该在 ubuntu 图像之上安装 python 或简单地使用来自 docker hub

的现有 python 图像

将您的 Dockerfile 更改为

FROM ubuntu
COPY . .
RUN apt-get update
RUN apt-get -y install python3
RUN apt-get -y install python3-pip
RUN pip install bottle
RUN /bin/bash -c "source venv/bin/activate"
ENTRYPOINT /bin/bash -c "python3 index.py"

试试这个然后告诉我。