30
loading...
This website collects cookies to deliver better user experience
Note: I am on Ubuntu 20.04.
The source code for the files that I am using is here
Expected:
Data is lost after killing the container
Execution:
Run the following command in your terminal-
docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql
docker -ps
to list all the running containers on your system.docker exec -it CONTAINER-ID mysql
create database DB_NAME; show databases; exit
/c
to clear out the inputs and exit
in order to exit from mysql.ls -a
in your working directory, and it will show you your created database.docker -ps
and kill the running container by executing docker kill CONTAINER_ID
.docker -ps
on the terminal, which shows that no container is up at the current moment.ls -a
in your working directory, you will not be able to see the database or any other file that you might have created.Expected:
Data is kept inside of the local folder.
Execution:
Run the following command in your terminal-
docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=true -v$(pwd)/mysql-data:/var/lib/mysql mysql
docker -ps
to list all the running containers on your system.docker exec -it CONTAINER-ID mysql
-it
is used frequently to tag images in docker.create database DB_NAME; show databases; exit
ls -a
in your working directory, and it will show you your created database.docker -ps
and kill the running container by executing docker kill CONTAINER_ID
.docker -ps
on the terminal, which shows that no container is up at the current moment.ls -a
in your working directory, you will notice that the created database still exits in the local folder.Expected:
Data is preserved inside the volume.
Execution:
Run the following command in your terminal-
docker run -d -e MYSQL_ALLOW_EMPTY_PASSWORD=true -v mysql/data:/var/lib/mysql mysql
in order to start up and run the container.
docker -ps
and then attach to the database using the command-docker exec -it CONTAINER-ID mysql
create database DB_NAME; show databases; exit
/c
to clear out the inputs inside mysql and exit
in order to exit from mysql.docker -ps
and kill the running container by executing docker kill CONTAINER_ID
.docker -ps
on the terminal, which shows that no container is up at the current moment.volume ls
. This command lists all the volumes present on our local machine.volume ls
on the terminal. In the output, we can see that our created database mysql-data still exists even after deleting the container.volume inspect VOLUME-NAME
Some additional resources for help:
Inspect Docker Volume
Digital Ocean on Docker Volumes