I'm in the process of migrating my VPS to a new provider due to my current one shutting down. Most of the files can be easily transferred, and I can restart the Docker containers without much hassle. However, I'm facing issues with moving my database files. I've updated the Docker compose file to use bind mounts and copied the old database files to the appropriate directory, but the new container isn't recognizing them. What's the best way to transfer database files into a new Docker installation? Any help would be appreciated!
4 Answers
If you need to ensure the correct permissions, here's a quick method: Stop the database container and use a command to back up your data volume with the correct ownership. Then, transfer the tar.gz backup to your new host and restore it there. This will help maintain all file permissions and the correct container version.
For MySQL, you should definitely use mysqldump. It's the standard way to export your database. Just make a dump and then import that into your new server once you've set it up.
It's best not to directly copy the data volume mounted by your database, as this contains internal runtime data. Instead, start your new SQL instance fresh and use the recommended export tool specific to your database, like pg_dump for Postgres or mysqldump for MySQL. This approach will require some downtime, so don't try to keep everything online during the process; just take that hour to do it right!
The safest method is to perform a database dump from your old server, which will create SQL files. You can then copy these files over and import them into your new setup. If you do decide to archive your database volume instead, ensure the DB container is stopped and maintain proper permissions when transferring the files.

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