简体   繁体   English

内部 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

I am trying to create 2x Docker containers:我正在尝试创建 2x Docker 容器:

  1. For my WEB API对于我的 WEB API
  2. For PostgreSQL DB对于 PostgreSQL 数据库

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.

相关问题 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:无法打开文件“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 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 无法打开文件'.manage.py':[Errno 2] 没有这样的文件或目录 - can't open file '.manage.py': [Errno 2] No such file or directory 无法打开文件 'manage.py': [Errno 2] 没有那个文件或目录 - Can't open file 'manage.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 python:无法打开文件“.manage.py”:[Errno 2] 没有这样的文件或目录 - python: can't open file '.manage.py': [Errno 2] No such file or directory Django 1.8 python:无法打开文件'manage.py':[Errno 2]没有这样的文件或目录 - Django 1.8 python: can't open file 'manage.py': [Errno 2] No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM