docker映射配置文件


1、创建一个my.cnf文件

[mysqld]
user=mysql
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

 2、启动的时候指定配置文件

--mount方式:

--mount type=bind,src=/mysql/conf/my.cnf,dst=/etc/my.cnf

-v方式

-v /mysql/conf/my.cnf:/etc/my.cnf
sudo docker run -p 3306:3306 -e TZ="Asia/Shanghai" --name mysql \
--privileged=true \
--mount type=bind,src=/mysql/conf/my.cnf,dst=/etc/my.cnf \
--mount type=bind,src=/mysql/logs,dst=/var/log/mysql \
--mount type=bind,src=/mysql/data,dst=/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:5.7