Search code examples
linuxdockermountcifs

Mounting CIFS under Docker container does not affect host-mounted volume


I'm trying to make a Docker image that logs onto a Kerio VPN and then mounts a remote samba directory onto /mnt.

The mounting is done using mount -t cifs -o username=USER,password=PWD //ABC/randomDirectory /mnt and it succeeds. When I list the contents of /mnt from the container itself I can see all the files and directories on the remote server, but when I list the host directory that has been mounted on the container when starting it (-v /absolute/path/to/mountpoint:/mnt), it comes up empty.

I tried adding a simple touch /mnt/test on the start of the ENTRYPOINT script, and that creates a file in /absolute/path/to/mountpoint and is even there when I list it from inside the container. Once I mount the CIFS, listing from inside the container provides all the files and directories on the remote, and listing from the host shows only the created test file.

It seems like the mount command inside the container "detaches" the docker volume.

EDIT: mounting to a subdirectory in the mounted volume doesn't work either


Solution

  • The volume can be specified to mount as shared by -v /local/path:/mnt:shared