Docker mount to folder overriding content

非 Y 不嫁゛ 提交于 2019-12-03 03:36:30

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 refelected 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 relected inside the container and similarly files edited inside the container /app/Config will be reflected in $configVolumePath on the host.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!