Size: 1633
Comment:
|
Size: 1658
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 66: | Line 66: |
read_only: true |
Docker Bind Mounts
dockerd(8) uses bind mounts to mount a host file or directory into a container.
Compare to Volumes.
Contents
Mounts
The syntax for mounting a file or directory into a container is:
docker run --detach --name=my-nginx \ --mount type=bind,src=/absolute/path/to/web/root,dst=/usr/share/nginx/html,readonly \ --mount type=bind,src=/absolute/path/to/app/binary,dst=/app,readonly \ nginx:latest
Note that the host file or directory must exist; an error will be raised otherwise.
When a bind mount targets an existing and non-empty directory in a container, the contents of that directory are obscured.
Volumes
An alternative syntax for mounting a file or directory is:
docker run --detach --name=my-nginx \ --volume /absolute/path/to/web/root:/usr/share/nginx/html:ro \ --volume /absolute/path/to/app/binary:/app:ro \ nginx:latest
This syntax is much shorter but...
the option is poorly named, as it can easily be confused with Volumes, which are a separate concept
if the host file or directory does not exist, dockerd(8) creates it as a directory on the host
Nonetheless the --volume option is frequently used in documentation.
Docker Compose
To use a bind mount with Docker Compose, try:
services: web: image: nginx volumes: - type: bind source: /absolute/path/to/web/root target: /usr/share/nginx/html read_only: true