Docker MySQL stores data in a local directory, and it's simple to map a local directory to a container
1. Plus-v parameter
$ docker run-d-e mysql_root_password=admin --name MYSQL -v /data/mysql/data:/var/lib/mysql -P 3306: 3306 MySQL
You can also specify a configuration file
Docker run-d-E mysql_root_password=admin --name MYSQL -v/data/mysql/my.cnf:/etc/mysql/my.cnf-v/< C6>data/mysql/data:/var/lib/mysql-p 3306: 3306 MySQL
In this way, the configuration file can be modified, but also to the existence of local directory, double benefit, the-v parameter can be used multiple times, each mapping a directory, in this manner, it is easy to configure.
Docker run-d-E mysql_root_password=admin --name MYSQL -v/data/mysql/my.cnf:/etc/mysql/my.cnf-v/< C2>data/mysql/data:/var/lib/mysql-p 3306: 3306 mysql --lower_case_table_names=1
The explanations are as follows:
-D container runs in the background
-e mysql_root_password=Admin config MYSQL ROOT password
-V maps the MySQL configuration file and datastore path to the host, persisting data
-P Port Mapping
--name define the name of the container
--lower_case_table_names=1 definition database does not differentiate between table name and case
User's steps:
Pull MySQL Image
Docker pull MySQL
Running MySQL
Docker run
--net=host
--restart=always
--privileged=true
-v/usr/docker_dat/mysql/data:/var/lib/mysql
--name MySQL
-P 3,306:3,306
-E Mysql_root_password=root
-v/etc/localtime:/etc/localtime:ro
-D MySQL--lower_case_table_names=1
3. Parameter description
--restart=always Follow Docker Boot
--privileged=true container root user has host root user rights
-V maps the host path to the container
-e mysql_root_password=root Setting the ROOT user password
-D Background Boot
--lower_case_table_names=1 setting table name parameter names and ignoring case
-v/etc/localtime:/etc/localtime:ro Setting the container time to synchronize with the host
Docker MySQL data persisted to local, setting no difference in table name capitalization