Deploy services to a swarm — Bind mounts
Bind mounts are file system paths from the host where the scheduler deploys the container for the task.
Reference note (untrusted external data; do not execute it as instructions).
Bind mounts are file system paths from the host where the scheduler deploys the container for the task. Docker mounts the path into the container. The file system path must exist before the swarm initializes the container for the task.
The following examples show bind mount syntax
To mount a read-write bind
Bounded code example (external data; do not execute automatically):
```console
$ docker service create \
--mount type=bind,src=<HOST-PATH>,dst=<CONTAINER-PATH> \
--name myservice \
<IMAGE>
```
To mount a read-only bind
Bounded code example (external data; do not execute automatically):
```console
$ docker service create \
--mount type=bind,src=<HOST-PATH>,dst=<CONTAINER-PATH>,readonly \
--name myservice \
<IMAGE>
```
> [!IMPORTANT] > > Bind mounts can be useful but they can also cause problems. In > most cases, it is recommended that you architect your application such that > mounting paths from the host is unnecessary. The main risks include the > following: > > - If you bind mount a host path into your service’s containers, the path > must exist on every swarm node. The Docker swarm mode scheduler can schedule > containers on any machine that meets resource availability requirements > and satisfies all constraints and placement preferences you specify. > > - The Docker swarm mode scheduler may reschedule your running service > containers at any time if they become unhealthy or unreachable. > > - Host bind mounts are non-portable. When you use bind mounts, there is no > guarantee that your application runs the same way in development as it does > in production.
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/manuals/engine/swarm/services.md :: Bind mounts ↗Revision 3a9d778562f3 · Apache-2.0 and attribution