wiki:use_hetzner_storage_box_docker_volume
Table of Contents
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 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
References
wiki/use_hetzner_storage_box_docker_volume.txt · Last modified: 2023/06/19 15:02 by antisa