Mount SMB/CIFS share within a Docker container

后端 未结 5 2015
遥遥无期
遥遥无期 2020-11-29 03:03

I have a web application running in a Docker container. This application needs to access some files on our corporate file server (Windows Server with an Active Directory dom

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 03:09

    Do not make your containers less secure by exposing many ports just to mount a share. Or by running it as --privileged

    Here is how I solved this issue:

    • First mount the volume on the server that runs docker.

    sudo mount -t cifs -o username=YourUserName,uid=$(id -u),gid=$(id -g) //SERVER/share ~/WinShare

    Change the username, SERVER and WinShare here. This will ask your sudo password, then it will ask password for the remote share.

    Let's assume you created WinShare folder inside your home folder. After running this command you should be able to see all the shared folders and files in WinShare folder. In addition to that since you use the uidand gid tags you will have write access without using sudo all the time.

    • Now you can run your container by using -v tag and share a volume between the server and the container.

    Let's say you ran it like the following.

    docker run -d --name mycontainer -v /home/WinShare:/home 2d244422164

    You should be able to access the windows share and modify it from your container now.

    To test it just do:

    docker exec -it yourRunningContainer /bin/bash

    cd /Home

    touch testdocfromcontainer.txt

    You should see testdocfromcontainer.txt in the windows share.

提交回复
热议问题