Docker Community Forums

Share and learn in the Docker community.

Writing to mounted cifs share from container taking up space on host machine

I have a cifs share mounted to my ubuntu server e.g.

In my container I mount a sub directory e.g.

My issue is that as I write to this directory from my container it works great but it seems to be confusing the host file system because


Grows in size with every file I write to the shared directory from the container. To make this matter worse, as I delete the files on the shared drive, the host does not pick up on this so /dev grows but never shrinks in kind.

This obviously presents a problem because Ubuntu thinks it’s run out of space but it hasn’t.

I can’t figure out what I’m doing wrong, but obviously this isn’t desired behavior.

Docker only abstracts away applications, whereas mounting filesystems happens at the kernel level and so can’t be restricted to only happen inside the container. When using --privileged, the mount happens on the host and then it’s passed through into the container.

Really the only way you can do this is to have the share available on the host (put it in /etc/fstab on a Linux machine, or mount it to a drive letter on a Windows machine) and have the host mount it, then make it available to the container as you would with any other volume.

Also bear in mind that mkdir -p “//myshare/folder name” is a semi-invalid path - most shells will condense the // into / so you may not have access to a folder called /myshare/folder name since the root directory of a Linux system is not normally where you put files. You might have better success using /mnt/myshare-foldername or similar instead.

An alternative could be to find a way to access the files without needing to mount them. For example you could use the smbclient command to transfer files between the Docker container and the SMB/CIFS share without needing to mount it, and this will work within the Docker container, just as you might use wget or curl to upload or download files, as is also commonly done in Dockerfiles.

@lewish95 thanks for the detailed response, I’ll dig deeper into mounting on the host to ensure that my issue doesnt lie there.