Docker – Mount Windows Network Share Inside Container [duplicate]

This question already has an answer here:

  • Mount SMB/CIFS share within a Docker container

    2 answers

  • Access webcam using OpenCV (Python) in Docker?
  • How to run GPGPU inside docker image with different from host kernel and GPU driver version
  • Why google drive change permission of the file and how to solve it?
  • How would one specify which containers to start and not to start in docker-compose? (docker run vs docker create)
  • How to add Dockerfile to a docker registry page?
  • How to deploy application to docker container on Linux server?
  • Docker Compose run a command
  • Why are my non-volume data in Docker container persistence after restarting the container?
  • How to enable code running in a docker container access files on the host on which the container is running?
  • Access Windows 2016 Server Container (Docker container) via GUI?
  • Why is docker stats CPU Percentage greater than 100 times number of cores
  • Spawn a new process in docker container which image is built from scratch
  • 2 Solutions collect form web for “Docker – Mount Windows Network Share Inside Container [duplicate]”

    You are correct that you can only use --privileged during docker run. You cannot perform mount operations without --privileged, ergo, you cannot perform mount operations during the docker build process.

    This is probably by design: the goal is that a Dockerfile is largely self contained; anyone should be able to use your Dockerfile and other contents in the same directory to generate the same image; linking things to an external mount would violate this restriction.

    However, your question says that you have an application that needs to read some data from a share so it’s not clear why you need the share mounted during docker build. It sounds like you would be better off building an image that will launch your application as part of docker run, and possibly use docker volumes to access the share rather than attempting to mount it inside the container.

    Haven’t used Docker so this may not apply, however if you list your share in /etc/fstab and include the user option, then you can allow unprivileged users to mount it, e.g. from your script.

    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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.