官方文檔摘錄(勿噴,僅供自己筆記)
官方文檔如下:
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必須
)文件就會被生效。