Docker mount to folder overriding content

First of all, docker volumes or bind mounts behave like linux mounts.

If the host volume/mount exists and contains files it will “override” whatever is in the container. If not the container files will be mirrored onto the host volume/mount and the container folder and the host will be in sync.
In both cases editing the files on the host will ALWAYS be reflected inside the container.

In your case, you can do the following:

docker volume create --driver local \
    --opt type=none \
    --opt device=$configVolumePath \
    --opt o=bind \
    config_vol

This will create a volume which will be persisted in $configVolumePath on the host.

When creating the container use that volume:

docker create --volume config_vol:/app/Config

What you will get is on startup, the host folder will be empty and the files from the image will be “copied” onto the host folder. Editing files in $configVolumePath will be reflected inside the container and similarly
files edited inside the container /app/Config will be reflected in $configVolumePath on the host.

Leave a Comment