{{tag>docker cifs "network storage" hetzner}}
====== Use Hetzner storage box as docker volume ======
First create the directory on the share e.g. //dock_vol//
mkdir /mnt/backup/dock_vol
Create volume with cifs driver
docker volume create \
--driver local \
--opt type=cifs \
--opt device=//uxxxxxx.your-storagebox.de/backup/dock_vol \
--opt o=addr=uxxxxxx.your-storagebox.de,iocharset=utf8,rw,username=uxxxxxx,password=xxxxxxxxxx,file_mode=0660,dir_mode=0660 \
--name cifs_volume
This is enough, you don't need to mount the share on host as well.
If the app running in container is running and trying to write as a different user than root, you will need to adjust the permissions in above command that creates volumes to ''...file_mode=0777,dir_mode=0777...'', as per [[https://docs.docker.com/storage/volumes/#create-cifssamba-volumes|this example]].
Ansible playbook task example:
- hosts: "myhost"
pre_tasks:
- name: Create docker volume on shared storagebox
docker_volume:
name: cifs_volume
driver_options:
type: cifs
device: "device=//uxxxxxx.your-storagebox.de/backup/dock_vol"
o: "addr=uxxxxxx.your-storagebox.de,iocharset=utf8,rw,username=uxxxxxx,password=xxxxxxxxxx,file_mode=0660,dir_mode=0660"
tags: volume
Test example
docker run -d \
--name=nginxtest \
-v cifs_volume:/usr/share/nginx/html \
nginx:latest
====== Tested on ======
* Docker 23.0.1
* ansible 2.9.27
====== See also ======
* [[wiki:write_custom_host_path_docker_container|Write to custom host path from Docker container]]
====== References ======
* https://docs.docker.com/storage/volumes/#create-cifssamba-volumes