Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker compose - can't find manage.py file

I want to create with docker-compose 2 Docker containers. 1 for DB (Mongo) and 1 for web (Django). Here are my files

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

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.

when i run docker-compose up it throws me the following error:

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.

Do you have an idea why docker-compose doesn't find my file when starting?

like image 557
Virtual Avatar asked Mar 03 '23 11:03

Virtual


1 Answers

The directory structure in your Dockerfile and docker-compose seems confusing. Another thing that is strange is you are able to see to file after docker exec.

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.

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

To debug:

  • remove mounting in docker-compose and check if it works
  • command: tail -f /dev/null set this command in docker-compose and verify your file location using docker exec
like image 183
Adiii Avatar answered Mar 11 '23 09:03

Adiii