Docker Community Forums

Share and learn in the Docker community.

Issue in persisting data created while running mysql image using Data Container


(Kallolchaudhuri) #1

I am trying to persist data created while running mysql images using Data Container.
Below are the steps followed :-
1. Created a Data Container :-
a. Docker File content is
FROM mysql:latest
VOLUME /var/lib/mysql
CMD [“true”]
b. docker create --name mysql_data -v /var/lib/mysql mysql

2. Started MySQL container using the data container
a. docker run --name mysqldb --volumes-from mysql_data -v /var/lib/mysql:/var/lib/mysql -e MYSQL_USER=mysql -e MYSQL_PASSWORD=mysql -e MYSQL_DATABASE=sample -e MYSQL_ROOT_PASSWORD=supersecret -it -p 3306:3306 mysql
b. docker exec -it mysqldb bash and then created few tables and populated data

3. Pushed Data Container Image and Database Image into Docker Hub
4. Removed the Data Container Image and Database Image from local
5. Pulled the Data Container Image and Database Image from Docker Hub
6. Now when I create the Data Container from the Image and then run the Database Image using the Data Container, I see DATA IS GONE.. CAN YOU PLEASE HELP HERE. I need to pull both Data and Database Containers from Hub.

  1. However, if Data Container is NOT Removed from Local and Database Image is only removed and replaced by Docker Hub, I CAN SEE THE DATA AFTER RUNNING THE DATA CONTAINER.

CAN YOU PLEASE HELP HERE. I need to pull both Data and Database Containers from Hub and Nothing else.
THANKS A LOT.