[英]Docker compose - can't find manage.py file
I want to create with docker-compose 2 Docker containers.我想用 docker-compose 创建 2 个 Docker 容器。 1 for DB (Mongo) and 1 for web (Django).
1 个用于 DB(Mongo),1 个用于 Web(Django)。 Here are my files
这是我的文件
docker-compose.yml docker-compose.yml
version: '3'
services:
db:
image: mongo
command: mongod
web:
build: code/
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
code/Dockerfile代码/Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY cleverInvestWeb/ /code/
In the directory code/cleverInvestWeb/ is my manage.py file from django.在目录code/cleverInvestWeb/ 中是我来自 django 的 manage.py 文件。
when i run docker-compose up
it throws me the following error:当我运行
docker-compose up
它会抛出以下错误:
web_1 | python: can't open file 'manage.py': [Errno 2] No such file or directory
When i start the container via Docker itself with docker exec -it dockerdiplom_web bash
and do an ls
there it shows the manage.py
file.当我使用
docker exec -it dockerdiplom_web bash
通过 Docker 本身启动容器并在那里执行ls
,它会显示manage.py
文件。
Do you have an idea why docker-compose doesn't find my file when starting?你知道为什么 docker-compose 在启动时找不到我的文件吗?
The directory structure in your Dockerfile and docker-compose seems confusing. Dockerfile 和 docker-compose 中的目录结构似乎令人困惑。 Another thing that is strange is you are able to see to file after
docker exec
.另一件奇怪的事情是您可以在
docker exec
之后看到 to file 。
You copy your code to COPY cleverInvestWeb/ /code/
in Dockerfile, and then mount the volume in Docker-compose to .:/code
so everything will be overide in the existing image on /code
location.您将代码复制到
COPY cleverInvestWeb/ /code/
中的COPY cleverInvestWeb/ /code/
,然后将 Docker-compose 中的卷挂载到.:/code
这样所有内容都将覆盖在/code
位置上的现有映像中。
I assume your python file place inside local directory cleverInvestWeb
so docker-compose boot up it will override the existing image code and your file update location will be code/cleverInvestWeb/manage.py
or /code/manage.py
我假设您的 python 文件位于本地目录
cleverInvestWeb
因此cleverInvestWeb
-compose 启动它将覆盖现有的图像代码,并且您的文件更新位置将是code/cleverInvestWeb/manage.py
或/code/manage.py
To debug:调试:
command: tail -f /dev/null
set this command in docker-compose and verify your file location using docker exec
command: tail -f /dev/null
在 docker-compose 中设置此命令并使用docker exec
验证您的文件位置将您的命令更改为
command: python code/manage.py runserver 0.0.0.0:8000
This is a common error among the Django beginners这是 Django 初学者常见的错误
The docker file ' docker-compose.yml ' configuration (shown at the beginning of this request) is alrigh... Except for the django project folder missing when calling the manage.py file! docker文件' docker-compose.yml '配置(在这个请求的开头显示)是正常的......除了调用manage.py文件时缺少django项目文件夹!
The Line should have been:该行应该是:
Explaination about Volumes named "/code" The Volume "/code" is building your application using the root of the Docker project folder:关于名为“/code”的卷的说明 卷“/code”正在使用 Docker 项目文件夹的根目录构建您的应用程序:
/home/user/Documents/youDockerProjectFolder = (Code) /home/user/Documents/youDockerProjectFolder = (代码)
Inside the "/home/user/Documents/youDockerProjectFolder" you should find the django project folder: yourDjangoProjectFolder/在“/home/user/Documents/youDockerProjectFolder”中,您应该找到 django 项目文件夹: yourDjangoProjectFolder/
Inside that folder you will find the manage.py... So it's normal to have to use yourDjangoProjectFolder/manage.py in order to call manage.py在该文件夹中,您会找到 manage.py ... 所以必须使用yourDjangoProjectFolder/manage.py来调用 manage.py 是正常的
MORE but not important for this solution Inside the Docker Project Folder another important file is found yourDjangoProjectFolder/youDjangoProjectFolder/settings.py对于此解决方案更多但并不重要在 Docker 项目文件夹中找到另一个重要文件 yourDjangoProjectFolder/youDjangoProjectFolder/settings.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.