Push your Local Database to Docker Container!

Push your Local Database to Docker Container!

Maheshwar Ligade's photo
Maheshwar Ligade
·May 29, 2022·

2 min read

Subscribe to our newsletter and never miss any upcoming articles

Play this article

Table of contents

  • Step 1:
  • Step 2:
  • Step 3:
  • Conclusion:

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:

https://www.youtube.com/watch?v=D60OxlK9lto&list=PLBpGB6ILbVMT8WfmCR7pVbV_XuWVVc1M7

Step 1:

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

Example

mysqldump --databases accounts > dev-account-dump.sql

Step 2:

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

Step 3:

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.

Conclusion:

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:

https://medium.com/techwasti

https://www.youtube.com/channel/UCiTaHm1AYqMS4F4L9zyO7qA

https://www.techwasti.com/

==========================**=========================

If this article adds any value for you then please clap and comment.

Let’s connect on Stackoverflow, LinkedIn, & Twitter.

Did you find this article valuable?

Support techwasti by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this