[英]having on running flask app on docker container : Error: python: can't open file '//run.py': [Errno 2] No such file or directory Docker Error
please see this link to see the folder structure: https://drive.google.com/file/d/1KceimcgGMN68Z0gDet2G6SzZIQUhkQ2G/view?usp=sharing请参阅此链接以查看文件夹结构: https : //drive.google.com/file/d/1KceimcgGMN68Z0gDet2G6SzZIQUhkQ2G/view?usp=sharing
Hi, I am having issue with running my flask app on docker container, please help.嗨,我在 docker 容器上运行我的烧瓶应用程序时遇到问题,请帮忙。 this is the Dockerfile code:这是 Dockerfile 代码:
from alpine:latest
RUN apk add --no-cache python3.9.7-dev \
&& apk add --no-cache py3-pip \
&& pip install --upgrade pip
WORKDIR /NewBackend
COPY . /NewBackend
RUN pip3 --no-cache-dir install -r requirements.txt
FROM python:3.9.7-slim
RUN apt-get update \
&& apt-get -y install libpq-dev gcc \
&& pip install psycopg2
EXPOSE 5000
#ENTRYPOINT ["python"]
CMD ["python","run.py"]
You're copying the files into the alpine container, which is not the final image.您正在将文件复制到 alpine 容器中,这不是最终图像。 Your final image has only libpq-dev, gcc and psycopg2 installed.您的最终映像仅安装了 libpq-dev、gcc 和 psycopg2。
Every time you use FROM, you're starting the image creation from scratch and only the last one is exposed.每次使用 FROM 时,您都是从头开始创建图像,并且只公开最后一个。 Multi-stage builds are used in order to avoid build dependencies on the final image and you may copy files from them using COPY.使用多阶段构建是为了避免构建对最终映像的依赖,您可以使用 COPY 从中复制文件。
I suggest you try the following Dockerfile:我建议您尝试以下 Dockerfile:
FROM python:3.9.7-slim
WORKDIR /NewBackend
COPY . /NewBackend
RUN pip3 --no-cache-dir install -r requirements.txt
RUN apt-get update \
&& apt-get -y install libpq-dev gcc \
&& pip install psycopg2
EXPOSE 5000
#ENTRYPOINT ["python"]
CMD ["python","run.py"]
If you'd really like to use multi-stage builds to avoid cluttering your image, I suggest you check how the files are moved from a intermediate container into the final image in this link: https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds如果您真的想使用多阶段构建来避免图像混乱,我建议您在此链接中检查文件如何从中间容器移动到最终图像: https : //docs.docker.com/develop /develop-images/multistage-build/#use-multi-stage-builds
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.