Docker - Mount Windows Network Share Inside Container
Question: I have a small Python application that I'd like to run on Linux in Docker
(using boot2docker for now). This application reads some data from my Windows
network share, which works fine on Windows using the network path but fails on
Linux. After doing some research I figured out how to mount a Windows share on
Ubuntu. I'm attempting to implement the dockerfile so that it sets up the
share for me but have been unsuccessful so far. Below is my current approach,
which encounters operation not permitted at the mount command during the build
process.

    
    
    #Sample Python functionality
    import os
    folders = os.listdir(r"\\myshare\folder name")
    
    #Dockerfile
    RUN apt-get install cifs-utils -y
    RUN mkdir -p "//myshare/folder name"
    RUN mount -t cifs "//myshare/folder name" "//myshare/folder name" -o username=MyUserName,password=MyPassword
    
    #Error at mount during docker build
    #"mount: error(1): Operation not permitted"
    #Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
    

**Edit** Not a duplicate of [Mount SMB/CIFS share within a Docker
container](http://stackoverflow.com/questions/27989751/mount-smb-cifs-share-
within-a-docker-container). The solution for that question references a fix
during `docker run`. I can't run `--privileged` if the docker build process
fails.

* * *

**Q: What is the correct way to mount a Windows network share inside a Docker
container?**

* * *


Answer: 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](https://docs.docker.com/userguide/dockervolumes/#mount-a-host-
directory-as-a-data-volume) to access the share rather than attempting to
mount it inside the container.

