1 Pull the official mysql5.7 image
docker pull mysql:5.7
2. Create a mysql container
Create a mapping directory of mysql locally
mkdir -p /root/mysql/data /root/mysql/logs /root/mysql/conf
Create a *.cnf file in /root/mysql/conf (call it whatever)
touch my.cnf
Create a container, map data, logs, and configuration files to the machine
docker run -p 3306:3306 --name mysql -v /root/mysql/conf:/etc/mysql/conf.d -v /root/mysql/logs:/logs -v /root/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
-d: run the container in the background
-p maps the port of the container to the port of the machine
-v mount host directory to container's directory
-e set parameters
3 Start the mysql container
docker start mysql
Check whether there are data files in the /root/mysql/data directory
ls