简体   繁体   English

Docker compose - 找不到 manage.py 文件

[英]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:调试:

  • remove mounting in docker-compose and check if it works删除 docker-compose 中的安装并检查它是否有效
  • 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:该行应该是:


command: python nameOfDjangoFolder/manage.py runserver 0.0.0.0:8000命令:python nameOfDjangoFolder/manage.py runserver 0.0.0.0:8000

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.

相关问题 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 compose - python:无法打开文件“manage.py”:[Errno 2] 没有这样的文件或目录 - Docker compose - python: can't open file 'manage.py': [Errno 2] No such file or directory python: 无法打开文件 'manage.py': [Errno 2] 编写时没有这样的文件或目录 docker - python: can't open file 'manage.py': [Errno 2] No such file or directory when compose docker 当运行 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 在 runserver 命令中找不到文件 manage.py - Docker-compose cannot find file manage.py in runserver command 内部 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-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 windows 10 专业版中的 Docker:python:无法打开文件“manage.py”:[Errno 2] 没有这样的文件或目录 - Docker in windows 10 pro: python: can't open file 'manage.py': [Errno 2] No such file or directory Django:manage.py找不到任何应用程序 - Django: manage.py can't find any apps 无法打开文件'.manage.py':[Errno 2] 没有这样的文件或目录 - can't open file '.manage.py': [Errno 2] No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM