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:
- We used uid=0 and gid=0 since the root user is being used inside the container
- cifs 3.0 was used to mount that Windows share, which was a Windows 11 in my tests
- 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:
- https://docs.docker.com/storage/bind-mounts/
- https://docs.docker.com/storage/volumes/
- https://forums.docker.com/t/how-to-map-lan-network-share-to-docker-volume/97276
- https://forums.docker.com/t/docker-compose-mount-samba-volume/132407
- https://stackoverflow.com/questions/42287408/how-to-mount-network-volume-in-docker-for-windows-windows-10
- https://www.reddit.com/r/docker/comments/vjp0h5/how_do_i_map_my_network_drive_to_a_docker/
- https://www.tutorialspoint.com/docker-add-network-drive-as-volume-on-windows