I'm needing to migrate my VPS to a new provider since my current one is shutting down. Most cases are straightforward where I can start fresh and simply copy files to the new VPS and restart my Docker containers. However, I have a specific database that needs to be moved which is proving to be tricky. I've modified the Docker Compose file for bind mounts and transferred the old database files into the designated directory, but the new container isn't recognizing them. What's the right method for transferring database files to a new Docker installation?
4 Answers
For MySQL, definitely go with mysqldump. Use the official export tools for the database you're working with. It makes things much easier!
The safest route is to create a database dump into SQL files from your old server and then copy and import those to the new server. If you prefer, you can stop the database container completely, archive the database volume, and transfer it over, making sure to preserve all permissions and use the correct container version.
It's better not to copy the actual data volume mounted by the database. That's internal runtime data and won't help you with your actual data. Instead, start with a clean SQL instance and use the export/import tools for your SQL provider, like pg_dump for PostgreSQL or mysqldump for MySQL. It's a good idea to consider this migration a downtime task, so don’t try to run differential imports while staying online; just take a short downtime for a smoother transition.
I don’t have the complete details here, but remember to look at permissions. You should stop the DB container before proceeding. You can make use of Docker commands to create and manage backups and ensure you maintain the correct UID and GID ownerships.

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