1

I'm looking for an option for persistent docker storage away from the server it's running on.

I know I can mount a CIFS share using a named volume and the local storage driver but these volumes just seem to be bind mounts and aren't managed by docker so you then have to deal with the user permissions issues that come with that.

Ideally this would be from a docker-compose.yml.

I'm open to any kind of target I can run locally really, I will probably be running it from my windows desktop but can setup an iscsi target or whatever is needed really. The aim is to centralize the data so it's more easily backed up and so i can focus on data persistence and not have to worry about the VMs themselves. I'm hoping to do this without complicating things over just using named local volumes.

Thanks in advance for any help you can provide!

Sam Foley
  • 66
  • 1
  • 4
  • Did you look at the [volume driver plugins](https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins)? – Gerald Schneider Dec 07 '21 at 17:07
  • @GeraldSchneider yeah none really do what I want, the closest is the normal local storage plugin mounting a cifs share (or smb in my case) but it's just a bind mount so the standard permissions issues with bind mounts come into play and would have to be resolved at least once for every different container, if not more frequently when things go wrong :( – Sam Foley Dec 07 '21 at 22:20

2 Answers2

1

Okay so I realised in the end that the reason this wasn't working for me and was breaking my container was because the container includes mongodb and mongodb will not work on a mount like this, there is a Github issue open for that.

So the below does work for me by running most of it locally but mounting the backups folder to shared storage, less than ideal as I'd have to restore a backup but also good enough as that's a simple process for my use case.

volumes:
  unifi:
  unifi_backup:
    driver_opts:
      type: cifs
      o: "username=DockerMounts,password=SuperSecurePassword,uid=1000,gid=1000"
      device: "//192.168.0.2/FastDockerVolumes/unifi/backup"
Sam Foley
  • 66
  • 1
  • 4
0

I initially specified the CIFS volume directly in my compose file, but then realized that in most scenarios as you need to manually remove any volume you want to reconfigure, you are probably better off using an externally-defined volume so that you're not married to CIFS in every deployment.

docker-compose stops namespacing externally-provided volumes, but we can work around that by requiring the volume name to be specified as an environment variable, presumably in your .env:

services:
  my-service:
    volumes:
      - data:/mnt/data
volumes:
  data:
    name: "${DATA_VOLUME?}"
    external: true

and then manually create the volume using e.g.:

# We might as well use the standard project-namespacing convention
DATA_VOLUME=compose-project_data
# N.B. you MUST use the addr option when relying on DNS resolution
docker volume create \
  --name $DATA_VOLUME \
  --driver local \
  --opt type=cifs \
  --opt "device=//remote.host/share/path" \
  --opt "o=addr=remote.host,domain=$DOMAIN,username=$USER,password=$PASS"
J Cracknell
  • 101
  • 2