[英]python: can't open file 'manage.py': [Errno 2] No such file or directory when compose docker
I run two different Apps in containers.我在容器中运行两个不同的应用程序。
Django ran just well. Django 跑得很好。 I configured my Flask App as follow:
我将我的 Flask 应用配置如下:
This Is a docker-compose.yml这是一个 docker-compose.yml
version: '3.8'
services:
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- 8001:5000
volumes:
- .:/app
depends_on:
- db
db:
image: mysql:5.7.22
restart: always
environment:
MYSQL_DATABASE: main
MYSQL_USER: username
MYSQL_PASSWORD: pwd
MYSQL_ROOT_PASSWORD: pwd
volumes:
- .dbdata:/var/lib/mysql
ports:
- 33067:3306
This also is my Dockerfile这也是我的 Dockerfile
FROM python:3.8
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app
CMD python main.py
Problem: When I run docker-compose up
the following error occurs问题:当我运行
docker-compose up
时出现以下错误
backend_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory
I don't know why it tries to open manage.py
file since it is Flask and not Django App.我不知道为什么它会尝试打开
manage.py
文件,因为它是 Flask 而不是 Django App。 I need your help.我需要你的帮助。 Thanks in Advance.
提前致谢。
I'm not sure how this will work for you but, I resolved this by changing my docker-compose.yml to have a command parameter, so it looks like this我不确定这对你有什么用,但是,我通过将 docker-compose.yml 更改为具有命令参数来解决这个问题,所以它看起来像这样
version: '3.8'
services:
backend:
build:
context: .
dockerfile: Dockerfile
command: 'python main.py' << Updated Line >>
ports:
- 8001:5000
volumes:
- .:/app
depends_on:
- db
db:
image: mysql:5.7.22
restart: always
environment:
MYSQL_DATABASE: main
MYSQL_USER: username
MYSQL_PASSWORD: pwd
MYSQL_ROOT_PASSWORD: pwd
volumes:
- .dbdata:/var/lib/mysql
ports:
- 33067:3306
I started a new Flask app(but this time on virtualenv) and my problem fixed:)我启动了一个新的 Flask 应用程序(但这次是在 virtualenv 上),我的问题已解决:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.