Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mount network Volume in Docker for Windows (Windows 10)

Tags:

docker

windows

We're working to create a standard "data science" image in Docker in order to help our team maintain a consistent environment. In order for this to be useful for us, we need the containers to have read/write access to our company's network. How can I mount a network drive to a docker container?

Here's what I've tried using the rocker/rstudio image from Docker Hub:

This works:

docker run -d -p 8787:8787 -v //c/users/{insert user}:/home/rstudio/foobar rocker/rstudio

This does not work (where P is the mapped location of the network drive): docker run -d -p 8787:8787 -v //p:/home/rstudio/foobar rocker/rstudio

This also does not work: docker run -d -p 8787:8787 -v //10.1.11.###/projects:/home/rstudio/foobar rocker/rstudio

Any suggestions?

I'm relatively new to Docker, so please let me know if I'm not being totally clear.

like image 739
KingOfTheNerds Avatar asked Feb 17 '17 00:02

KingOfTheNerds


People also ask

How do I make my docker container accessible from network?

To make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, use the --publish or -p flag. This creates a firewall rule which maps a container port to a port on the Docker host to the outside world.


2 Answers

I know this is relatively old - but for the sake of others - here is what usually works for me. for use - we use a windows file-server so we use cifs-utils in order to map the drive. I assume that below instructions can be applied to nfs or anything else as well.

first - need to run the container in privileged mode so that you can mount remote folders inside of the container (--dns flag might not be required)
docker run --dns <company dns ip> -p 8000:80 --privileged -it <container name and tag>

now, (assuming centos with cifs and being root in the container) - hop into the container and run:

install cifs-utils if not installed yet
yum -y install cifs-utils

create the local dir to be mapped
mkdir /mnt/my-mounted-folder

prepare a file with username and credentials
echo "username=<username-with-access-to-shared-drive>" > ~/.smbcredentials
echo "password=<password>" > ~/.smbcredentials

map the remote folder
mount <remote-shared-folder> <my-local-mounted-folder> -t cifs -o iocharset=utf8,credentials=/root/.smbcredentials,file_mode=0777,dir_mode=0777,uid=1000,gid=1000,cache=strict

now you should have access

hope this helps..

like image 157
lev haikin Avatar answered Oct 05 '22 04:10

lev haikin


I have been searching the solution the last days and I just get one working.

I am running docker container on an ubuntu virtual machine and I am mapping a folder on other host on the same network which is running windows 10, but I am almost sure that the operative system where the container is running is not a problem because the mapping is from the container itself so I think this solution should work in any SO.

Let's code.

First you should create the volume

docker volume create 
--driver local 
--opt type=cifs 
--opt device=//<network-device-ip-folder>
--opt o=user=<your-user>,password=<your-pw>
<volume-name>

And then you have to run a container from an image

 docker run 
 --name <desired-container-name> 
 -v <volume-name>:/<path-inside-container>
 <image-name>

After this a container is running with the volume assignated to it, and is mapped to . You create some file in any of this folders and it will be replicated automatically to the other.

In case someone wants to get this running from docker-compose I leave this here

services:
  <image-name>:
    build: 
      context: .
    container_name: <desired-container-name> 
    volumes:
       -  <volume-name>:/<path-inside-container>
    ...

volumes:
  <volume-name>:
    driver: local
    driver_opts: 
      type: cifs 
      device: //<network-device-ip-folder>
      o: "user=<your-user>,password=<your-pw>"

Hope I can help

like image 25
Julian Antonucci Avatar answered Oct 05 '22 05:10

Julian Antonucci