6

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" 
4
  • Why don't you try to use the full path to django-admin? Commented Feb 13, 2017 at 3:35
  • Thanks for the suggestion. Still no success. But again the same behavior, when I logon onto the container, it works... Commented Feb 13, 2017 at 7:15
  • Are you trying to execute django-admin or django-admin.py ? Commented Feb 14, 2017 at 6:26
  • Yes. Same thing. Both ways work now. Please see my answer. Commented Feb 14, 2017 at 17:35

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Why the downvote? This clearly solves my problem and I described how to do it.
idk, it helped me.
2

What I ran :

docker-compose run app djando-admin.py startproject app 

Output:

sh: djando-admin.py: not found

Solution:

sudo docker-compose run app django-admin startproject app . 

Try to use sudo.

1 Comment

for future readers ~> docker-compose run django django-admin startproject core .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.