I recently faced a hard drive corruption in my media virtual machine and decided to take this chance to transition from VMWare to Proxmox, building my VMs anew. Although I'm recreating the VMs, I'd like to preserve my Docker containers and their data. Rebuilding the data doesn't sound appealing! In my Docker setup, I initially created a main folder for each app and used the docker-compose file to set up subfolders for data, configs, etc., keeping the app itself inside the container. I ran into issues when I last tried to move my Docker containers, which left me confused. I had copied the app folder structure to a backup site, but when I set it up on the new VM, I faced permission problems and empty databases. I hear that using a 'docker compose up' followed by downing the container and moving the data, then doing a second 'docker compose up' might be correct. Should I also use tar for preserving permissions? What's the best method to successfully move my containers without losing data, including my recipes in Mealie?
3 Answers
There are a couple of ways to handle persistent data: either by bind mounting a host folder into the container or using a Docker volume. For your migration, stopping the containers first and then using a tarball to compress and transfer your data is effective. You could tar the necessary folders, transfer the tarball to the new server, and then extract it. If the data is in a volume, consider starting a temporary container attached to those volumes to dump them into tar files for easier transfer. It's also crucial to maintain user permissions to prevent those frustrating permission issues you ran into before!
To keep your data intact, use Docker volumes for persistent storage so your data exists outside the container. When you're ready to migrate, make sure to stop your containers to avoid any conflicts. You can then transfer the contents of those volumes to the new host. If you’re unsure about the process you used before, it’s advisable to check if you included the right options for copying. Using 'cp -a' is good, just ensure you're doing this while the containers aren't running to avoid data discrepancies.
Before moving any data, definitely shut down your containers. Use a command like 'rsync -avX' to maintain the permissions and structure while copying your data over. It's a very reliable way to move your files without losing any configurations or data.

Related Questions
How To Get Your Domain Unblocked From Facebook
How To Find A String In a Directory of Files Using Linux