简体   繁体   中英

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? is there something wrong with my 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:

sudo docker build -t priceengine .
sudo docker run -dp 1500:1500 priceengine
sudo docker start 2d7f96017801

So, my # Production Image was correct?

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 ). Just use a normal Dockerfile for this (no multistage).

Try adding a line with EXPOSE 1500 before your ENTRYPOINT . This exposes the port from the docker container to your host system. Can you access it then?

Edit: Also not unimportant, how are you running your Docker container? Can you show your docker run command?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM