1

I am following the docker/django tutorial: https://docs.docker.com/compose/django/

I set up a project directory C:\docker_test and configured docker-compose.yml, Dockerfile and requirements.txt as described in the guide.

This is the contents of docker-compose.yml:

version: '3'

services:
  db:
    image: postgres
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"
    depends_on:
      - db

And the contents of the Dockerfile:

FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip --proxy=http://mycorpproxy:80 install -r requirements.txt
COPY . /code/

When I run docker-compose run web django-admin startproject composeexample . it executes as expected but I do not see a composeexample directory created. If I attempt to re-run the command I get this error:

CommandError: /code/manage.py already exists, overlaying a project or app into an existing directory won't replace conflicting files

I don't have a /code/ directory on my local machine... where is it located?

Thanks!

EDIT: This does not feel like much of an answer but here is how I got this working again. I uninstalled docker and re-installed. Our Sec dept keeps a pretty tight grip on the host FW rules so I had to get a helpdesk person to adjust some firewall rules on my host and we got it working. I had to do the same last time I installed docker but something seems to have gone right this time. In a case like this it would be nice if there was a way to not use a network share for drive access.

rev_it_up
  • 75
  • 2
  • 11
  • 1
    Show us your docker-compose.yml. You most likely didn't correctly specified volumes. – jozo Dec 18 '19 at 21:20
  • @jozo Thanks for asking. I just added the contents of docker-compose.yml to the original post. Let me know if you see anything. I was suspecting an issue with the Dockerfile so I'll add that too. – rev_it_up Dec 19 '19 at 12:23
  • 1
    `/code/` directory is in your docker container. You can run `docker-compose run web pwd` and `docker-compose run web ls -l` to see your directory inside docker container. – d0niek Dec 19 '19 at 12:28
  • Thanks for the info @d0niek! I can see code and the composeexample directories were created inside the container. On my old PC, the composeexample folder was also created in my project folder and the tutorial seems to indicate that would be the case. So for me the question still stands, if the code folder is created in the docker image, why isn't it in the local folder also? – rev_it_up Dec 19 '19 at 13:30
  • 1
    You've mounted your local project directory `.` to the container's directory `/code`. That is a symbolic link. It isn't _in_ your local directory, it _is_ your local directory. – Joel Magnuson Dec 19 '19 at 22:14
  • @JoelMagnuson that is why I am confused. How can manage.py and the other files created by the django-admin startproject command be in the /code directory and not the local directory on my machine? – rev_it_up Dec 20 '19 at 14:39
  • @rev_it_up I would first remove or change the `volumes:` mount in the yml file because you're overwriting the container's /code directory with the project directory. Your Dockerfile already copied your project's contents into the container's `/code` directory and then you overwrite that directory during deployment. – Joel Magnuson Dec 20 '19 at 19:39
  • This question pops up all over the place and it seems to be an issue with the tutorial itself. The issues go back 5 years but I haven't yet seen anyone actually answer how they fixed it. – seth Oct 16 '20 at 21:23

0 Answers0