[英]Multistage Dockerfile Python
so I got trouble here, I've deployed my multistage dockerfile with python:3.8-slim-buster
, but I can't access this URL?所以我在这里遇到了麻烦,我已经使用
python:3.8-slim-buster
部署了我的多级 dockerfile ,但是我无法访问这个 URL? is there something wrong with my Dockerfile?我的 Dockerfile 有什么问题吗?
# Build Image
FROM python:3.8-slim-buster as builder
RUN apt-get update --fix-missing
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y libgl1-mesa-dev python3-pip git
RUN mkdir /usr/src/app
WORKDIR /usr/src/app
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip3 install -U setuptools
RUN pip3 install --upgrade pip
RUN pip3 install -r ./requirements.txt
COPY . /usr/src/app
# Production Image
FROM python:3.8-slim-buster as app
COPY --from=builder /usr/src/app /usr/src/app
WORKDIR /usr/src/app
ENTRYPOINT gunicorn --bind 0.0.0.0:1500 --workers 1 --threads 8 main:app --worker-class uvicorn.workers.UvicornH11Worker --preload --timeout 60 --worker-tmp-dir /dev/shm
This is how I run my Docker:这就是我运行 Docker 的方式:
sudo docker build -t priceengine .
sudo docker run -dp 1500:1500 priceengine
sudo docker start 2d7f96017801
So, my # Production Image
was correct?那么,我的
# Production Image
是正确的吗?
I'm assuming your app depends on the installed packages, if so it will not work with a multistage built.我假设您的应用程序依赖于已安装的软件包,如果是这样,它将不适用于构建的多阶段。 Multistage builds are only helpful to avoid adding build-time dependencies to the final image.
多阶段构建仅有助于避免将构建时依赖项添加到最终映像。 Here you need the
apt
packages and requirements.txt
packages at runtime ( ENTRYPOINT
).在这里,您需要运行时的
apt
包和requirements.txt
包( ENTRYPOINT
)。 Just use a normal Dockerfile for this (no multistage).只需为此使用普通的 Dockerfile(无多级)。
Try adding a line with EXPOSE 1500
before your ENTRYPOINT
.尝试在您的
ENTRYPOINT
之前添加一行EXPOSE 1500
。 This exposes the port from the docker container to your host system.这会将 docker 容器的端口暴露给您的主机系统。 Can you access it then?
那你可以访问它吗?
Edit: Also not unimportant, how are you running your Docker container?编辑:同样重要的是,您如何运行 Docker 容器? Can you show your
docker run
command?你能显示你的
docker run
命令吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.