Download image
Using the docker pull mysql:5.7.21
pull MySQL image, use docker images
the view-owned image after the download is successful:
?
Downloaded MySQL image.
Create a new folder for persistence
1. Create a new folder $DEV_HOME/docker/mysql
.
2, give it permission chmod 777 $DEV_HOME/docker/mysql
, it seems that if you do not give it permission, Docker can not save the data inside.
?
The database file is then written directly to the local
Create a container
Use the command: docker run --name mysql -p 3306:3306 -v $DEV_HOME/docker/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123 -d mysql:5.7.21
create a container called "mysql".
-p 3306:3306
: Maps local 3306 to port 3306 of the container.
-v $DEV_HOME/docker/mysql:/var/lib/mysql
: Maps the local directory to the container directory.
-e MYSQL_ROOT_PASSWORD=123
: The password of the root user of MySQL.
I learn docker (1)--using MySQL