How to mount a Windows share inside a Docker container

Let’s assume that you had a windows share and you needed to be able to access that share from within one of your containers, here are the steps that you need to follow:

First of all, create a docker volume that mounts that Windows share:

docker volume create --driver local --opt type=cifs --opt o=username={user},password={password},uid=0,gid=0,vers=3.0 --opt device=//{IP}/{Folder} my_windows_share

Where:

  1. We used uid=0 and gid=0 since the root user is being used inside the container
  2. cifs 3.0 was used to mount that Windows share, which was a Windows 11 in my tests
  3. my_windows_share is the name of the volume mapped to the Windows share

Eventually, you just run any container you want and map it to that volume:

docker run -it -v my_windows_share:/{target_folder_inside_container} {image_name}

As an example for both commands:

docker volume create --driver local --opt type=cifs --opt o=username=User,password=TY321,uid=0,gid=0,vers=3.0 --opt device=//10.0.0.129/Users my_windows_share

docker run -it -v my_windows_share:/windows_share ubuntu:latest

That’s it, Enjoy!

Sources:

Unknown's avatar

About Ahmed Tawfik

Cybersecurity Professional, Systems Engineer, OSS & Linux Geek
This entry was posted in docker, Windows and tagged , , . Bookmark the permalink.

Leave a comment