Reputation: 1705
I've been successfully mounting volumes on Windows 10 in various projects recently using the example docker-compose.yml file below. For a new project today I needed to mount a folder from the Z:/ drive (a network mounted drive which appears as \\IP.IP.IP.IP\public\data (Z:)
when I navigate to that area in Windows File Explorer.
When I edit the volumes to point to locations on Z: (e.g. in the second docker-compose.yml below), the volumes are not mounted properly and are empty folders when I connect to the container via the CLI.
Any advice on getting the Z: drive folders to mount properly would be great, thanks.
Working docker-compose.yml file:
version: '3.1'
services:
db:
image: mysql:8.0.25
container_name: db
restart: always
secrets:
- mysql_root
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root
MYSQL_DATABASE: donuts
TZ: "Australia/NSW"
volumes:
- mysql-data:/var/lib/mysql
- ./mysql-init.sql:/docker-entrypoint-initdb.d/mysql-init.sql
network_mode: "host"
voyager_donuts:
container_name: voyager_donuts
build:
context: .
dockerfile: Dockerfile
image: voyager_donuts
network_mode: "host"
environment:
TZ: "Australia/NSW"
volumes:
- c:/Users/MYUSERNAME/data/DonutsCalibration:/voyager_calibration
- c:/Users/MYUSERNAME/data/DonutsLog:/voyager_log
- c:/Users/MYUSERNAME/data:/voyager_data
- c:/Users/MYUSERNAME/data/DonutsReference:/voyager_reference
volumes:
mysql-data:
secrets:
mysql_root:
file: ./secrets/mysql_root
Broken volumes docker-compose.yml file:
version: '3.1'
services:
db:
image: mysql:8.0.25
container_name: db
restart: always
secrets:
- mysql_root
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root
MYSQL_DATABASE: donuts
TZ: "Australia/NSW"
volumes:
- mysql-data:/var/lib/mysql
- ./mysql-init.sql:/docker-entrypoint-initdb.d/mysql-init.sql
network_mode: "host"
voyager_donuts:
container_name: voyager_donuts
build:
context: .
dockerfile: Dockerfile
image: voyager_donuts
network_mode: "host"
environment:
TZ: "Australia/NSW"
volumes:
- z:/RAW/DonutsCalibration:/voyager_calibration
- z:/RAW/DonutsLog:/voyager_log
- z:/RAW:/voyager_data
- z:/RAW/DonutsReference:/voyager_reference
volumes:
mysql-data:
secrets:
mysql_root:
file: ./secrets/mysql_root
Upvotes: 10
Views: 12629
Reputation: 3469
According to this forum thread you would have to use something like this to be able to mount network shares:
volumes:
foldermix:
driver_opts:
type: cifs
o: username={smbuser},password={smbpass},uid={UID for mount},gid={gid for mount},vers=3.0
device: //Share1/FolderMix
See also the docker documentation for Samba/CIFS volumes.
Of course, if you really need the indirection to mount the network drive instead of the network share, i.e. because the drive can be mounted to different shares or you do not want to put your credentials into the Docker-Compose file, this will not solve the issue.
Upvotes: 10