Install the MySQL service using the official Docker image
1 Pull MySQL image, use netease acceleration address
Docker pull HUB.C. 163. Com/library/mysql:5.7
2 Renaming a mirror name
Docker tag HUB.C. 163. Com/library/mysql:5.7 mysql:5.7
3 Creating a directory for mounting
sudo mkdir /my/mysql/datadir #用于挂载mysql数据文件 sudomkdir /my/mysql/CONF.D # To mount the MySQL profile sudochown yaoren:docker/my #修改/my directory Owner
4 Creating a container using mirrors
Docker run--name MySQL5. 7 3306:3306 -v/my/mysql/datadir:/var/lib/mysql-v/my/mysql/conf.d:/etc/mysql/conf.d-e MYSQL_ root_password=123456 -D MySQL:5.7
Command parsing:
--name: Container Name
--P: Mapping host host ports
-V: Mount the host directory to the container directory
-E: Setting the environment variable, specifying the root password here
-D: Running containers in the background
5 The test is successful
mysql-h192. 168.18. -p3306-uroot-p
Docker Install Mysql