Reprint: https://www.cnblogs.com/notejava/p/7124189.html
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数据文件
sudo mkdir/my/mysql/conf.d #用于挂载mysql配置文件
sudo chown yaoren:docker/my #修改/my directory Owner
4 Creating a container using mirrors
Docker run--name mysql5.7-p 3306:3306-v/my/mysql/datadir:/var/lib/mysql-v/my/mysql/conf.d:/etc/mysql/conf.d-e MYSQ L_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.2.102-p3306-uroot-p
Installing the MySQL service with Docker