no django app created when following the docker-compose tutorial

你。 提交于 2021-02-18 22:01:19

问题


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?


回答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/



回答2:


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



回答3:


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.




回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/31565640/no-django-app-created-when-following-the-docker-compose-tutorial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!