This tutorial is quick guide which will help you to solve very intresting problem, how you can copy data dump from your legacy database setup to docker or containerised docker instance. In this tutorial, I am going to demostrate mysql local instance dump to dockerised container instance.
If you are not aware about, how to setup your development environment or local environment using docker then please visit below youtube playlist:
Take data dump from your existing mysql instance. I have mysql 5.7 on my local and same docker image version I am using.
mysqldump --databases db1 db2 db3 > dump.sql
mysqldump --databases accounts > dev-account-dump.sql
Make sure that docke is running and mysql container is up and running in your local or whereever based your usecase. Follow article to setup mysql setup using docker.
To check container is runnig or not
docker ps -a
Docker is container platform and it having own filesystem and to check that use below command
docker exec -ti <container_id> <your_command>
You should move our dump file inside the Docker container. I would like to create a new folder in the root directory.
docker exec -ti <container_id> mkdir dataDumps
then move the dump file to this folder.
docker cp <name_file>.dump <container_id>:/dataDumps
Now data dump is available in your container, let us import it.
docker exec -ti <container_id> mysql -u <username> <database_name>
mysql -U <username> -d <databasename> < dataDumps/<name_file>.dump
Verify the data dump is restored or imported successful or not. If not successful then it would be issue with mostly database version or database name but debug based on stacetrace and exceptions.
In this article, you leared two things setup database instance using docker and how you can restore or import data dump in the docker instance database.
More such articles:
If this article adds any value for you then please clap and comment.