简体   繁体   中英

Why can “docker-compose run” create files outside the container?

I am new to Docker and I am learning Docker with its official docs.

In one tutorial , it explains how to create a Django project with Docker.

What I can not understand is the command below.

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

The doc says it will create a Django project inside a container, and those new created files will be in local filesystem.

My question is why those new created files will be in local system if they are created in a container?

That's because in your docker-compose.yml file you're creating an image called web with a shared volume which maps your current directory (.) to /code directory of the created container.

volumes:
  - .:/code

That means that all files that are in /code directory (the directory where you create your project inside in the container) will be also in your local system under project directory.

Take a look to data volumes in Docker documentation to see things clearly:

https://docs.docker.com/engine/tutorials/dockervolumes/

Because in the docker-compose.yml it's defined a volume:

volumes:
       - .:/code

The "dot" before the colon means the current directory in your computer (host) relative to the Dockerfile and docker-compose.yml. And the /code is the directory inside the container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM