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?
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:
command: tail -f /dev/null
set this command in docker-compose and verify your file location using docker exec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With