Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a network drive from docker container

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.

like image 703
Marsilinou Zaky Avatar asked Oct 26 '25 00:10

Marsilinou Zaky


1 Answers

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
like image 137
indris Avatar answered Oct 27 '25 14:10

indris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!