Reusable Anchor Binds
Overview
When working with storage in Docker, there are several ways to mount host directories or shares into containers. This section outlines different mounting strategies and explains how to make volume mounts reusable across multiple containers.
Static Volume Mount
A static volume mount is the simplest way to connect a host directory to a container.
Example (pseudo code):
io:
image: repo.moovit24.de:443/mcp_io:4.10.2.0
restart: always
volumes:
-mnt/helmut-share:/Volumes/helmut4-shareThis setup mounts the specified host directory directly into the container. It’s easy to configure and works well for simple use cases.
However, it’s static, meaning that any changes to the mounted location (such as a re-mounted network share) may not automatically be reflected inside the container without restarting it.
Dynamic Bind Mount
A more flexible and recommended approach is to use a dynamic bind mount, which provides better propagation of changes from the host to the container. For further information see: Dynamic Share Mounts in Docker
Example (pseudo code):
io:
image: repo.moovit24.de:443/mcp_io:4.10.2.0
restart: always
volumes:
- type: bind
bind:
propagation: rslave
source: /mnt/helmut4-share
target: /Volumes/helmut4-shareThis configuration allows the container to dynamically reflect updates made to the mounted share on the host system.
It’s particularly useful when multiple network shares need to be mounted into Docker.
The main drawback is that each container requiring these mounts must define all the bind configurations individually — which can lead to long and repetitive YAML files.
Reusable x-binds
When multiple containers share the same mounts, reusable bind definitions can significantly simplify your Docker stack configuration. By defining bind mounts once using YAML anchors, you can reference them in any number of services.
Pseudo example:
x-binds:
helmut4-share: &helmut4-share
type: bind
bind:
propagation: rslave
source: /mnt/helmut4-share
target: /Volumes/helmut4-share
mam-share: &mam-share
type: bind
bind:
propagation: rslave
source: /mnt/mam-share
target: /Volumes/mam-share
playout: &playout
type: bind
bind:
propagation: rslave
source: /mnt/playout
target: /Volumes/playout
fx:
image: repo.moovit24.de:443/mcp_fx:4.x.x.x
volumes:
- *helmut4-share
io:
image: repo.moovit24.de:443/mcp_io:4.x.x.x
volumes:
- *helmut4-share
- *mam-share
- *playout
hc:
image: repo.moovit24.de:443/mcp_hc:4.x.x.x
volumes:
- *playoutBenefits of Using Anchors
Centralized configuration: All bind definitions are declared once at the top of the stack file.
Consistency: Ensures all containers use the exact same mount paths and options.
Easy maintenance: Updating a single bind definition automatically affects all containers referencing it.
Cleaner YAML: Reduces redundancy and keeps stack files shorter and easier to read.
Last updated