Change Docker volume location for a container reddit / selfhosted ---------------------------------------------------------------------- nathan12581 · 2023-12-21 08:40 I run Ubuntu VM on Proxmox for Docker. I have come to the realisation that two of my most important Docker container's data volumes (SQL and Vaultwarden) aren't backed up outside of my Promox's generic backup of a VM. I would like to organise my containers to follow this structure (please let me know if this is a good strategy): \~/Docker// Where I keep all docker-compose files in \~/Docker/compose So for example, for Vaultwarden: The Config Directory (if needed) would be: \~/Docker/Vaultwarden/config The Data Directory (where the /data path in the container will be mapped to) would be: \~/Docker/Vaultwarden/data This will allow me to backup this whole Docker directory to another system so I have a VM backup and a specific Docker backup. My current problem is that for both my sql and Vaultwarden containers, their volumes are mounted to the default docker directory, for example: /var/lib/docker/volumes/Vaultwarden/\_data How would I change these directories safely? Another issue is that I believe I have some errors in Docker permissions as when trying to access /var/lib/docker on my non-root account, I get a Permission denied error and every time I execute a docker command, I'd need to add sudo at the start of every command. TIA ---------------------------------------------------------------------- nik_h_75 · 2023-12-21 09:15 1.Shut down running docker containers 2. Rsync -av [source folder] [destination] 3. Change volume location in compose file(s) to new destination 4. Start containers ---------------------------------------------------------------------- nathan12581 · 2023-12-21 09:17 I happened to use Portainer to start up my SQL container so did not use compose for that, I suppose I can just simply map the new directory when editing the container to the new destination also? ---------------------------------------------------------------------- nik_h_75 · 2023-12-21 09:18 Yes ---------------------------------------------------------------------- marmata75 · 2023-12-21 09:18 This. And regarding the permission, that sound right. Docker runs as root and you normal user needs to escalate permission via sudo to operate on it and access its folders. ---------------------------------------------------------------------- nathan12581 · 2023-12-21 09:28 Thank you for your help. Do you happen to know anything about the permission error? I doubt I’ll be able to copy anything from /var/lib/docker with it ---------------------------------------------------------------------- Floroform · 2023-12-21 09:41 Try adding your non root user to the docker group ---------------------------------------------------------------------- ben-ba · 2023-12-21 11:01 U have bind mount and volumes. For volumes, Stop Edit /etc/docker/daemon.json Move data Start ---------------------------------------------------------------------- nathan12581 · 2023-12-21 11:02 Okay I’ll take a look, thank you ---------------------------------------------------------------------- ben-ba · 2023-12-21 11:02 U shouldn't. Move the data with sudo... ---------------------------------------------------------------------- nathan12581 · 2023-12-21 11:48 Given that we use Rsync to sync the two folders, would it be easier to keep all containers pointing to their default volume and just use Rsync to get the organisation I want and the ability to backup the entire \~/Docker folder? ---------------------------------------------------------------------- tenekev · 2023-12-21 11:51 If I read this right, you want to transition from [Docker Volumes](https://docs.docker.com/storage/volumes/) to [Docker Bind Mounts](https://docs.docker.com/storage/bind-mounts/)? You can copy the data from a container's volume with the following command: `docker cp CONTAINER:/container/dir /host/dir`. Then you need to remap the paths in your container config. If you want to move the whole Docker root directory, [here is a guide](https://stackoverflow.com/a/76316505/5260184). Personally, I keep /var/lib/docker and my /appdata directories as separate drives that I can resize when needed while the rest of the OS stays almost the same. ---------------------------------------------------------------------- nathan12581 · 2023-12-21 11:56 I was just going to ask, what are the best practises? For example, for Vaultwarden, I'm thinking of taking moving /var/lib/docker/volumes/Vaultwarden/\_data to \~/Docker/Vaultwarden/data Do the same for every container that has persistent storage. Then from then on when I create more containers, I create a folder for it within the \~/Docker/ folder and use that directory instead of using Docker volumes. Now, I can backup this entire \~/Docker folder every hour? ---------------------------------------------------------------------- tenekev · 2023-12-21 12:09 Yes, that's the gist of it. I linked the Docker docs for you to read. When I was new to this, it was much more reasonable for me to mount everything as bind mounts and browse the directories with a file browser on the host. As I grew accustomed to CLI, I stopped relying on the file browser and gradually shifted to using Docker Volumes. Both can be backed up easily because both are just directories. Volumes more so because they are better managed by Docker. You will also get less permission problems with Volumes. ---------------------------------------------------------------------- nathan12581 · 2023-12-21 12:12 Well thank you very much for your help! Much appreciated I will look at the link too. What is your setup then? Do you directly backup the entire /var/lib/docker folder or just the /var/lib/docker/volumes folder? Is there any other advantage to using docker volumes and backing up that directory instead of bind mounts other than it’s possibly better managed by docker? ---------------------------------------------------------------------- Accomplished-Lack721 · 2023-12-21 12:30 Unless I'm misunderstanding you, that would have the compose files treating what were originally volumes as bind mounts after moving them. I'm not sure what cans of worms that may or may not open up. You can edit the docker default volume location in etc/docker/daemon.json and point it to where you're moving those volumes. Alternately, you could use symlimks to let docker think it's still accessing things in the old location. I'd use the -a flag in rsync to make sure you're moving over all attributes when relocating the files. ---------------------------------------------------------------------- tenekev · 2023-12-21 13:37 I run my docker in an LXC but either way, I just run a backup job via Proxmox Backup Server and it backs up everything. I would like to implement a better, more granular, backup system though. Haven't gotten around to implementing [Nautical Backup](https://github.com/minituff/nautical-backup)