I have two running docker containers. one container has MySQL with data, another one container has Java web application in Tomcat.
How to clone MySQL container to another Docker host with data?
Tried Save/Load method. but no success because doesn't have data
but Java web application container is working
The docker way to save a container is using docker commit. However:
The commit operation will not include any data contained in volumes mounted inside the container.
Thus data saved in volumes won't be part of the commited container. This is the case for the MySQL docker image which saves the data under /var/lib/mysql and declares it as a docker volume.
There is a two step solution:
Commit the container using docker commit into a new image and transfer this image to the other machine.
Copy the data folder from the old container using docker cp <mysql-container>:/var/lib/mysql ./mysql-data and transfer the mysql-data folder to the new machine. When starting the new container
on the new host, run it using docker run -v ./mysql-data:/var/lib/mysql .... This will mount the data folder from the old container, and you should get an identical container with data.
Have you tried creating data Volume container? Mount volume directory to mysql container
docker create -v /var/lib/mysql --name mysqldata mysql
Refer this link for more details https://www.melvinvivas.com/using-docker-data-volume-with-a-mysql-container/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With