简体   繁体   English

在docker容器上运行flask应用程序:错误:python:无法打开文件'//run.py':[Errno 2]没有这样的文件或目录Docker错误

[英]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.

相关问题 Docker容器无法运行,错误:python3:无法打开文件“ flask run --host = 0.0.0.0”:[Errno 2]没有此类文件或目录 - Docker container fails to run, Error : python3: can't open file 'flask run --host=0.0.0.0': [Errno 2] No such file or directory 内部 Docker 容器 - python:无法打开文件 './services/web/manage.py':[Errno 2] 没有这样的文件或目录 - Inside Docker Container - python: can't open file './services/web/manage.py': [Errno 2] No such file or directory 在docker上运行时,Python烧瓶重新加载器“Errno 2没有这样的文件或目录”错误 - Python flask reloader “Errno 2 No such file or directory” error when running on docker python:无法打开文件“manage.py”:[Errno 2] 没有这样的文件或目录 docker-compose run - python: can't open file 'manage.py': [Errno 2] No such file or directory docker-compose run 如何解决 docker 的 PyCharm 错误“无法打开文件 'path/to/file.py': [Errno 2] No such file or directory”? - How to solve PyCharm error with docker "can't open file 'path/to/file.py': [Errno 2] No such file or directory"? 当运行 docker-compose up 我得到 python: can't open file 'manage.py': [Errno 2] No such file or directory - When run docker-compose up I get python: can't open file 'manage.py': [Errno 2] No such file or directory Docker compose - python:无法打开文件“manage.py”:[Errno 2] 没有这样的文件或目录 - Docker compose - python: can't open file 'manage.py': [Errno 2] No such file or directory docker-web-1 | python:无法打开文件'/code/manage.py':[Errno 2] 没有那个文件或目录 - docker-web-1 | python: can't open file '/code/manage.py': [Errno 2] No such file or directory python:无法打开文件'main.py':[Errno 2]没有这样的文件或目录-docker - python: can't open file 'main.py': [Errno 2] No such file or directory - docker python: 无法打开文件 '//ML_project.py': [Errno 2] Docker 中没有这样的文件或目录 - python: can't open file '//ML_project.py': [Errno 2] No such file or directory in Docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM