Docker: Mounting a Windows File share to a Container

docker

This document helps to mount a folder shared by a Windows server, to a folder in a CentOS container.

  • Share a folder from the Windows server, so that it can be accessed from any other Windows laptop using the following URL: \\192.168.0.150\myshare
  • The username to access the share is “user1” and the password “mypass”

Procedure to mount the share to a server where Docker is running.

  • Create a new user in the server.
  • Let us assume the UIG that was assigned is 5000 and group is 6000
  • Create a new folder in the server named “/theshare”
    [root@dcos_bootstrap /] mkdir /theshare

Now mount the Windows share to “/theshare”. The below method is temporary mount. You will have to add entries in fstab to make it permanent.
[root@dcos_bootstrap /] mount.cifs \\\\192.168.0.150\\myshare /theshare -o user=user1,pass=”Smypass”,uid=5000,gid=6000

Verify if the share got mounted properly
[root@dcos_bootstrap /] df -h

See if you can view the files stored in Windows share “\\192.168.0.150\myshare” in the CentOS server’s folder “\myshare“. Verify if you can add files in it.

Now let us bring a CentOS container, attaching the folder “/theshare” in the base server to “/mnt” in the container that will be deployed.
[root@dcos_bootstrap /] docker run -v /lib_core:/mnt -it centos

Login to the container and see if all the files shared by the Windows server is visible