You are on page 1of 2

#Hello_folks,

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.

 -v $(pwd):/var/lib/mysql: This part specifies a volume mount. It maps the current


directory ($(pwd)) on the host machine to the /var/lib/mysql directory inside the
container. This is typically used to persist data outside of the container, in this case,
for the MySQL database data.

 -e MYSQL_ROOT_PASSWORD=******: This part sets an environment variable


within the container. It sets the MYSQL_ROOT_PASSWORD environment variable
to the specified value (******). This is used to set the root password for the MySQL
database server running inside the container.

 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

You might also like