[英]Inside Docker Container - python: can't open file './services/web/manage.py': [Errno 2] No such file or directory
I am trying to create 2x Docker containers:我正在尝试创建 2x Docker 容器:
I am using docker-compose
in order to build these containers.我正在使用
docker-compose
来构建这些容器。 Even though I can successfully build them using docker-compose build
command, whenever I go to inspect the logs using docker-compose logs -f
command, I am getting the following error message:尽管我可以使用
docker-compose build
命令成功构建它们,但每当我 go 使用docker-compose logs -f
命令检查日志时,我都会收到以下错误消息:
...
db_1 | 2020-08-19 12:39:07.681 UTC [45] LOG: database system was shut down at 2020-08-19 12:39:07 UTC
db_1 | 2020-08-19 12:39:07.686 UTC [1] LOG: database system is ready to accept connections
web_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory
nlp-influencertextanalysis_web_1 exited with code 2
Everything seems fine with db container, but for some reason inside web container Python cannot locate manage.py file. db 容器似乎一切正常,但由于某种原因在 web 容器内 Python 找不到 manage.py 文件。 Here is my file structure:
这是我的文件结构:
And here is code for my docker-compose.yml
:这是我的
docker-compose.yml
的代码:
version: '3.7'
services:
web:
build: ./services/web
command: python manage.py run -h 0.0.0.0
volumes:
- ./services/web/:/usr/src/app/
ports:
- 5000:5000
env_file:
- ./.env.dev
depends_on:
- db
db:
image: postgres:12-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=user1
- POSTGRES_PASSWORD=test123
- POSTGRES_DB=influencer_analysis
volumes:
postgres_data:
And here is my code for Dockerfile
:这是我的
Dockerfile
代码:
FROM python:3.8.1-slim-buster AS training
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install system dependencies
RUN apt-get update && apt-get install -y netcat
RUN pip install --upgrade pip
COPY ./requirements.txt /usr/src/app/requirements.txt
RUN pip install -r requirements.txt
# install NLTK dependencies
RUN python -c "import nltk; nltk.download('punkt')"
# copy project
COPY . /usr/src/app/
WORKDIR /usr/src/app/experiments
RUN python train.py --data data/HaInstagramPostDetails.xlsx --update 1
I should note that I've printed out all fines that are located in /usr/src/app
when train.py
is executed with RUN
command from Docker file, and manage.py
is there.我应该注意,当使用 Docker 文件中的
RUN
命令执行train.py
时,我已经打印出位于/usr/src/app
中的所有罚款,并且manage.py
在那里。
I believe the problem is that you have changed the working directory at the end of your Docker file.我认为问题在于您更改了 Docker 文件末尾的工作目录。
You can try to give an exact path to your manage.py file or.您可以尝试提供您的 manage.py 文件的确切路径或。 Change the working directory in the Docker file at the end that directs to the app directory.
修改Docker文件最后指向app目录的工作目录。
I think there is problem while changing the Working directory.我认为更改工作目录时出现问题。 It should have been
应该是
WORKDIR /usr/src/app/web/experiments
based on the folder structure. WORKDIR /usr/src/app/web/experiments
基于文件夹结构。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.