Binding named volumes to external drives

Hi,

I have a Docker compose file in which I define named volumes that my containers use. Recently I ran out of disk space on my VPS and decided to add an external storage medium to the system, and use that as the location for one of the Docker compose defined named volumes (used for backups on my system).

I bound the named volume to the external storage medium, and am able to see files that get placed inside the volume show up on the external storage medium. So far so good.

However, it looks like the files are still being placed on the main system disk (under /var/lib/docker/volumes/docker_vol-backups), which beats the whole purpose of storing the files on an external drive.

Here is the relevant part of where the volume is defined inside the Docker compose file:

...
volumes:
  vol-backups:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: ${DOCKER_VOL_BACKUPS_PATH}
...

The path variable DOCKER_VOL_BACKUPS_PATH is defined inside a .env file stored along side the Docker compose file, and points to the mountpoint /mnt/backups.

Here is a composite screenshot of ncdu showing the size of var and mnt before and after a having run docker compose up and then triggered a backup operation which places a 8.7 GiB archive file on the vol-backups volume.
ncdu_size_difference

The archive file counts towards both the storage on /mnt/backups and on the main system disk (under /var/lib/docker)

Am I doing something wrong with the binding, or is this working as intended?

All help in debugging this would be most appreciated.

  • ncdu follows symlinks to external drives unless you use -x to exclude external drives.
  • I don’t see you mention how you moved data to the new drive from the original volume. Simply running docker compose up will not move already saved data
  • Also worth noting that if you just changed the original volume definition, a docker compose up will not change the volume until you delete the original volume so a new volume with the same name can be created with the new parameters.
1 Like

Thank you for the quick reply rimelek.

You’re right, running ncdu with -x I now see that the files are only being stored on the external mount.

The files were originally moved manually over from the default volume location to the external mount.

However, looking back I think I probably forgot to delete the volume before running the changed compose file, since my primary drive ran out of space again when scheduled backups were triggered later on.

That, in combination with me not using the correct flag on ncdu caused me to think the setup was somehow incorrect (compose file was correct but lacked a delete) and at that point I deleted the volume, ran the compose file again and used ncdu incorrectly again (compose file was correct, state was correct but the signal from ncdu was incorrect).

Thank you for the help, you probably saved the rest of my Sunday!