I have a problem starting a django project inside a docker container. My Dockerfile looks as follows:
FROM python:2.7
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
EXPOSE 8000
The requirements.txt
consists of the single line Django
which install django successfully.
My docker-compose.yml
has the following content:
version: '2'
services:
web:
build: ./web
command: python manage.py runserver 0.0.0.0:8000
ports:
- "8000:8000"
volumes:
- ./web:/code
To create a project I am calling:
docker-compose run web python django-admin.py startproject web .
which crashes with the following message:
python: can't open file 'django-admin.py': [Errno 2] No such file or directory
Also this
docker-compose run web django-admin.py startproject web .
crashes with
ERROR: Cannot start service web: oci runtime error: container_linux.go:247: starting container process caused "exec: \"django-admin.py\": executable file not found in $PATH"
It seems to me that there is an error in the $PATH
when executing the container like this. When I use the interactive mode -it
, I am able to call the django-admin
from this folder. Is the PATH
not set correctly or am I doing something else wrong here? The Dockerfile
is in the directory web
.
Edit: After the suggestion in the comment, I tried to run the django-admin
with the full path:
root@935ca5543589:/code# which django-admin
/usr/local/bin/django-admin
Still no change:
docker-compose run web /usr/local/bin/django-admin startproject web .
ERROR: Cannot start service web: oci runtime error: container_linux.go:247: starting container process caused "exec: \"/usr/local/bin/django-admin\": stat /usr/local/bin/django-admin: no such file or directory"
The answer is very simple actually. I had an error in my Dockerfile
when I ran the project first. After changing the Dockerfile
, docker-compose
did not rebuild the image automatically which I was assuming. Even rebuilding with docker build
did not solve this. Only after deleting the whole image, a rebuild was forced and gave me the correct result.
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