mirror of https://github.com/docker/docs.git
Merge pull request #15925 from moxiegirl/carry-14234
Closes #14234 and updates text
This commit is contained in:
commit
bace51571f
|
@ -95,47 +95,57 @@ if the volume is read/write.
|
||||||
In addition to creating a volume using the `-v` flag you can also mount a
|
In addition to creating a volume using the `-v` flag you can also mount a
|
||||||
directory from your Docker daemon's host into a container.
|
directory from your Docker daemon's host into a container.
|
||||||
|
|
||||||
>**Note**: If you are using Docker Machine on Mac or Windows, your Docker daemon
|
```
|
||||||
>only has limited access to your OS X/Windows filesystem. Docker Machine tries
|
$ docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py
|
||||||
>to auto-share your `/Users` (OS X) or `C:\Users` (Windows) directory - and so
|
```
|
||||||
>you can mount files or directories using `docker run -v
|
|
||||||
>/Users/<path>:/<container path> ...` (OS X) or `docker run -v
|
|
||||||
>/c/Users/<path>:/<container path ...` (Windows). All other paths come from your
|
|
||||||
>virtual machine's filesystem.
|
|
||||||
|
|
||||||
$ docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py
|
This command mounts the host directory, `/src/webapp`, into the container at
|
||||||
|
`/opt/webapp`. If the path `/opt/webapp` already exists inside the container's
|
||||||
|
image, the `/src/webapp` mount overlays but does not remove the pre-existing
|
||||||
|
content. Once the mount is removed, the content is accessible again. This is
|
||||||
|
consistent with the expected behavior of the `mount` command.
|
||||||
|
|
||||||
This will mount the host directory, `/src/webapp`, into the container at
|
If you are using Docker Machine on Mac or Windows, your Docker daemon has only limited access to your OS X or Windows filesystem. Docker Machine tries
|
||||||
`/opt/webapp`.
|
to auto-share your `/Users` (OS X) or `C:\Users` (Windows) directory. So,
|
||||||
|
you can mount files or directories on OS X using.
|
||||||
|
|
||||||
> **Note:**
|
```
|
||||||
> If the path `/opt/webapp` already exists inside the container's image, its
|
docker run -v /Users/<path>:/<container path> ...
|
||||||
> contents will be replaced by the contents of `/src/webapp` on the host to stay
|
```
|
||||||
> consistent with the expected behavior of `mount`
|
|
||||||
>
|
|
||||||
> When using Boot2Docker on Windows through git bash, there might be an issue with the
|
|
||||||
> way the source directory name is parsed. You can fix it by using a double slash at
|
|
||||||
> the beginning of the source directory name as explained in [issue #12751](https://github.com/docker/docker/issues/12751)
|
|
||||||
|
|
||||||
This is very useful for testing, for example we can
|
On Windows, mount directories using:
|
||||||
mount our source code inside the container and see our application at work as
|
|
||||||
we change the source code. The directory on the host must be specified as an
|
```
|
||||||
absolute path and if the directory doesn't exist Docker will automatically
|
docker run -v /c/Users/<path>:/<container path> ...`
|
||||||
|
```
|
||||||
|
|
||||||
|
All other paths come from your virtual machine's filesystem. For example, if
|
||||||
|
you are using VirtualBox some other folder available for sharing, you need to do
|
||||||
|
additional work. In the case of VirtualBox you need to make the host folder
|
||||||
|
available as a shared folder in VirtualBox. Then, you can mount it using the
|
||||||
|
Docker `-v` flag.
|
||||||
|
|
||||||
|
Mounting a host directory can be useful for testing. For example, you can mount
|
||||||
|
source code inside a container. Then, change the source code and see its effect
|
||||||
|
on the application in real time. The directory on the host must be specified as
|
||||||
|
an absolute path and if the directory doesn't exist Docker will automatically
|
||||||
create it for you.
|
create it for you.
|
||||||
|
|
||||||
> **Note:**
|
Docker volumes default to mount in read-write mode, but you can also set it to
|
||||||
> This is not available from a `Dockerfile` due to the portability
|
be mounted read-only.
|
||||||
> and sharing purpose of built images. The host directory is, by its nature,
|
|
||||||
> host-dependent, so a host directory specified in a `Dockerfile` probably
|
|
||||||
> wouldn't work on all hosts.
|
|
||||||
|
|
||||||
Docker volumes default to mount in read-write mode, but you can also set it to be mounted read-only.
|
```
|
||||||
|
$ docker run -d -P --name web -v /src/webapp:/opt/webapp:ro training/webapp python app.py
|
||||||
$ docker run -d -P --name web -v /src/webapp:/opt/webapp:ro training/webapp python app.py
|
```
|
||||||
|
|
||||||
Here we've mounted the same `/src/webapp` directory but we've added the `ro`
|
Here we've mounted the same `/src/webapp` directory but we've added the `ro`
|
||||||
option to specify that the mount should be read-only.
|
option to specify that the mount should be read-only.
|
||||||
|
|
||||||
|
>**Note**: The host directory is, by its nature, host-dependent. For this
|
||||||
|
>reason, you can't mount a host directory from `Dockerfile` because built images
|
||||||
|
>should be portable. A host directory wouldn't be available on all potential
|
||||||
|
>hosts.
|
||||||
|
|
||||||
### Mount a host file as a data volume
|
### Mount a host file as a data volume
|
||||||
|
|
||||||
The `-v` flag can also be used to mount a single file - instead of *just*
|
The `-v` flag can also be used to mount a single file - instead of *just*
|
||||||
|
@ -238,4 +248,3 @@ combine Docker with the services available on
|
||||||
repositories.
|
repositories.
|
||||||
|
|
||||||
Go to [Working with Docker Hub](/userguide/dockerrepos).
|
Go to [Working with Docker Hub](/userguide/dockerrepos).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue