Professional Documents
Culture Documents
Persist Data in Docker
Persist Data in Docker
If you kill the docker container accidentally and you want to persist the data then
Don’t worry,
Here is the #solution
Volume (Database) Backup: If your database stores its data in a Docker volume, you can still
access the data even after the container is killed. You can use,
“docker run -d -v $(pwd):/var/lib/mysql -e MYSQL_ROOT_PASSWORD=******
mysql:5.7”
And press enter.
Detail explanation of the above command:
docker run: This command is used to create and start a new Docker container based
on a Docker image.
-d: This flag stands for "detached mode". It tells Docker to run the container in the
background, so you can continue using your terminal.
mysql:5.7: This is the name of the Docker image to run the container from. In this
case, it's the official MySQL Docker image tagged with version 5.7. This will pull the
MySQL 5.7 image from Docker Hub if it's not already available locally, and then start
a container based on it.
So, altogether, this command starts a detached Docker container based on the MySQL
5.7 image, mounts the current directory on the host machine to store MySQL data
persistently, and sets the root password for the MySQL database server running inside
the container.
See the magic your database is backup successfully.
#happylearning #docker #docker_container_backup