2

How can I access files on a shared network drive from docker container?

I tried:

docker run --rm -it --name my_app -v  //shared_drive_name:/opt/local/shared_drive my_app:1.0 /bin/bash

Also I tried method mentioned here: Docker add network drive as volume on windows

The directory /opt/local/shared_drive is created but empty. I tried different variations of slashes since the host is win and docker running linux. I am connected to the VPN from the host to access these drives.

Marsilinou Zaky
  • 1,038
  • 7
  • 17

1 Answers1

1

I have this script for mounting Windows shared folders in Ubuntu Docker container. You have to copy the script in your image. Then you should run the container, and after that call these commands:

docker exec container_name mkdir -p %shared folder inside docker path%
docker exec container_name /bin/bash /~path to your script~/mount_folder.sh %username% %password% %network_path% %docker_path%

For instance:

docker exec container_name /bin/bash /~path to your script~/mount_folder.sh "Admin" somePassword //192.168.7.1/shared_folder /data

Script is (mount_folder.sh):

#!/bin/bash

set -e

USERNAME=${1}
PASSWORD=${2}
NETWORK_PATH=${3}
DOCKER_PATH=${4}

mount -t cifs -o rw,username="${USERNAME}",password="${PASSWORD}",vers=3.0,nolock $NETWORK_PATH $DOCKER_PATH
indris
  • 34
  • 2