Recently I had a need to mount a CIFS volume as a docker volume: The summary is that I wanted to use photoview to index photos on my NAS. This led to a lot of google searching, which ultimately told me it was perfectly possible, but not a lot of detail on the how.
Requirements
If you're on linux, make sure to: sudo apt-get install cifs-utils
Word of Warning
The biggest difference between doing this in docker and using a simple mount -t cifs
is that
the docker mount point must be the IP address and can't be the hostname. Some googling
eventually told me that this may be due to restrictions in the kernel, but I haven't verified myself.
Example
Command
docker volume create \
--driver local \
--opt type=cifs
--opt device=//192.168.8.103/public \ # IMPORTANT: This must be an IP, can't be a hostname
--opt "o=username=guest,password=guest" \
cifstest
docker run -it --rm -v cifstest:/mnt busybox
docker-compose
And bonus photoview docker-compose stack behind traefik!
version: '3.5'
services:
photoview:
image: viktorstrate/photoview:2
restart: always
networks:
- traefik-bridge
volumes:
- db:/app/db
- cache:/app/cache
- photos:/photos
environment:
- PHOTOVIEW_DATABASE_DRIVER=sqlite
- PHOTOVIEW_SQLITE_PATH=/app/db/photoview.db
- PHOTOVIEW_LISTEN_PORT=80
- PHOTOVIEW_MEDIA_CACHE=/app/cache
- MAPBOX_TOKEN=xxx
labels:
- "traefik.http.routers.photoview.rule=Host(`photoview`)"
volumes:
db: {}
cache: {}
photos:
driver: local
driver_opts:
type: cifs
device: //192.168.8.131/public
o: username=guest,password=guest,ro
networks:
traefik-bridge:
external: true
name: traefik-bridge
See Also
- https://forums.docker.com/t/docker-volume-create-with-local-cifs-driver/41226
- https://github.com/moby/moby/pull/39250