10

I'm following the docker-compose tutorial, to try and figure out how to get a django app to deploy: http://docs.docker.com/compose/django/

And everything's going smoothly (the app even works!) but the django project folder composeexample isn't created in my local project directory.

I'm left with a working "It Works!" page after running:

$ docker-compose run web django-admin.py startproject composeexample .

But I can't continue to edit the composeexample/settings.py, as the tutorial suggests: The folder doesn't exist on my machine (it does exist in the container, but it's no good to me there!)

Is the tutorial wrong? Did I not follow it right?

Thanks!

UPDATE:

Here's the problem, I'm using docker-machine to run this whole process through a remote docker instance. Are the rules about local folder sharing different when using a remote docker machine?

0atman
  • 3,298
  • 4
  • 30
  • 46
  • I guess you want to use `volumes` using `docker-compose` + `docker-machine` Maybe [this answer](http://stackoverflow.com/questions/30040708/how-to-mount-local-volumens-in-docker-machine#answer-30512262) is what you are looking for. – Alexis N-o Jul 22 '15 at 16:19

5 Answers5

1

You need to set up a dockerfile so that when you do a docker build, it copies your local code onto the container. To get started, you will need to copy the files from container to local. Look here for that. Or just overwrite the directory with your own django app

Copying files from host to Docker container

example:

FROM python:2.7
RUN mkdir /code
WORKDIR /code
ADD . /code/
Community
  • 1
  • 1
RustyShackleford
  • 25,262
  • 6
  • 22
  • 38
  • 1
    ie, the tutorial doesn't mention copying the generated code from container to local directory. Shouldn't changes be synced back to the local directory automatically? – 0atman Jul 22 '15 at 14:23
  • 1
    @Oatman don't forget the "." period when running `$ docker-compose run web django-admin.py startproject composeexample` – RustyShackleford Jul 22 '15 at 14:44
  • Thank you, I've double-checked, and that was a typo in my question, rather than a command I ran badly :-P If I run it again, it says `/code/manage.py already exists` – 0atman Jul 22 '15 at 14:45
  • 1
    I just ran through the tutorial quickly, it does work and adds composeexample folder to your local system. Just make the 3 files first, then run `docker-compose run web django-admin.py startproject composeexample . ` from that directory. – RustyShackleford Jul 22 '15 at 14:49
  • Oh dear, I'll tear everything down and start from scratch, give me a moment! – 0atman Jul 22 '15 at 14:50
  • Oh! I see what I'm doing! I am using docker-machine to do this all remotely. Would that change things? – 0atman Jul 22 '15 at 14:57
  • I'm not familiar with docker-machine – RustyShackleford Jul 22 '15 at 15:10
  • 1
    No problem, I've updated the Q with the problem. On a different note, you should try it, it's amazingly simple cloud orchestration for docker. https://www.docker.com/docker-machine – 0atman Jul 22 '15 at 15:18
  • I don't think I'm using docker-machine and I'm also having this issue - how did you ultimate solve it? – seth Oct 16 '20 at 21:40
0

ADD . /code/ in docker file will be actually mount your local working directory inside the docker image. So you can make changes to code inside your working directory and same will be updated inside the docker container as working directory is mounted inside the same.

Use dockerfile as shown in tutorial to generate the image and use the same image for creating container.

thinkingmonster
  • 5,063
  • 8
  • 35
  • 57
0

I am hitting the same issue, of the mount /code not showing up. I am using docker (Docker version 1.8.1, build d12ea79) on mac (mac os x yosemite 10.10.5)

Followed for Docker installation: https://docs.docker.com/installation/mac/

Followed for Django part: https://docs.docker.com/compose/django/

f$ docker-compose run web django-admin.py startproject composeexample .
    ...........
    ... Removing details for brevity ...
    ...........
Removing intermediate container 515d53d20d29
Step 6 : ADD . /code/
 ---> ea2b28ba6ebc
Removing intermediate container 6d6f0f9e2fe0
Successfully built ea2b28ba6ebc

f$ ls
Dockerfile   docker-compose.yml   requirements.txt
mihirv
  • 9
  • 1
0

Had the same issue, and that is because I changed the folder name "/code" in Dockerfile, but forget to change folder name in docker-compose.yum file. So be sure the folder name in the 2 files are the same.

And actually the container(and all the files) is already created in /var/lib/docker/overlay2/.../diff/code/, that is why the log mentioned about "Successfully built ...", but not copied back to the folder where you trigger the cmd. Hope this helps.

zhihong
  • 1,808
  • 2
  • 24
  • 34
0

I just had this issue on docker with WSL and tracked it down - it was an issue with volume mounting. Basically to solve this you need to create your project directory in WSL on the mounted c volume on not in a "native" WSL directory. In my case this meant creating my project directory here: /c/Users/seth/proj_dir

You can read more about mounting issues in this excellent WSL/Docker tutorial (search for "Create and modify the new WSL configuration file" and then search again for "docker-compose up": https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly

seth
  • 2,741
  • 3
  • 20
  • 15