docker-- The volume mount configuration mysql
1, first create two folders in the root directory, which is created my.cnf configuration file config folder. data folders to store data files, be sure to empty.
/docker/mysql/config/、/docker/mysql/data
2, modify the my.cnf file
[mysqld]
the User = MySQL must begin with two lines.
More configurations can to dockerhub official mysql / mysql-server mirroring source View
https://hub.docker.com/r/mysql/mysql-server
[mysqld]
user=mysql
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
3, execute the following command to mount the volume
docker run -d -p 3306:3306 --name mysql01
-e MYSQL_ROOT_PASSWORD="password"
-e MYSQL_USER="LZL"
-e MYSQL_PASSWORD="pwd123"
-v=/docker/mysql/config/my.cnf:/etc/my.cnf
-v=/docker/mysql/data:/var/lib/mysql
mysql/mysql-server
-v a roll, map a local folder to the container. localhost: container former is a native file: a file which is the container.
4, start some problems
After the start, it found by docker ps container and does not start .
docker ps -a to view all containers, container found in the exit status .
At this point we see some error messages vessel through docker logs mysql01.
It found to be insufficient permissions, causing the vessel to start immediately stop.
docker run -d -p 3306:3306 --name mysql01
--privileged=true
-e MYSQL_ROOT_PASSWORD="password"
-e MYSQL_USER="LZL"
-e MYSQL_PASSWORD="pwd123"
-v=/docker/mysql/config/my.cnf:/etc/my.cnf
-v=/docker/mysql/data:/var/lib/mysql
mysql/mysql-server
Solution: - privileged = true added to the parameter authorization.
When modifying the configuration of the time, simply modify /docker/mysql/config/my.cnf file, restart vessel configured to take effect.