I know we can mount a folder into a docker container like this:
docker run -v /home/user:/home/user <image>
But it will mask everything that is present in the container's /home/user
.
Is it possible to mount in such a way that if the file or folder is present in host machine's /home/user/
, it will be mounted; everything else will be retained from the container?
For example, suppose I have the following contents in my host and container respectively:
Host
/home/user/.ssh
/home/user/.config
/home/user/code-server # v2
Container
/home/user/apps/web-server
/home/user/code-server # v1
I would like to have a union of these after mounting:
/home/user/.ssh
/home/user/.config
/home/user/apps/web-server # because the container has it.
/home/user/code-server # because the host has it.