官方文档摘录(勿喷,仅供自己笔记)
官方文档如下:
The MySQL startup configuration is specified in the file /etc/mysql/my.cnf
, and that file in turn includes any files found in the /etc/mysql/conf.d
directory that end with .cnf
. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf
. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d
inside the mysql container.
If /my/custom/config-file.cnf
is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):
docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf
and /etc/mysql/conf.d/config-file.cnf
, with settings from the latter taking precedence.
说白了就是:比如挂载随主机/my/custom
目录到容器/etc/mysql/conf.d
目录,然后在宿主机目录/my/custom
创建的config-file.cnf
(名字无所谓,结尾.cnf必须
)文件就会被生效。