如何覆盖标准 mysql 5.7 容器配置
How to override standard mysql 5.7 container configuration
我无法替换标准 mysql 5.7 容器中的标准 /etc/my.cnf
文件。
我是 运行 一个 mysql 5.7 容器(标准 Docker HUB 映像)。
我想替换 etc/my.cnf
文件以启用主从操作。
我想通过挂载 docker-compose.yml
文件中的卷来实现。
新的my.cnf
应该是:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
# Replication and mirroring settings
server-id = 1
auto_increment_increment = 3
auto_increment_offset = 0
log_bin = /var/log/mysql/log-bin
log_bin_index = /var/log/mysql/log-bin.index
binlog_format = row
expire_logs_days = 10
log_slave_updates
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
在 docker-compose.yml
我有以下几行:
mysql:
image: mysql/mysql-server:5.7
container_name: rucio-mysql
volumes:
- ./mysql-config/my-master.cnf:/etc/my.cnf
environment:
- MYSQL_ROOT_PASSWORD=pass
- MYSQL_ROOT_HOST=%
路径正确,但容器启动并立即退出。
提前致谢,
滑动
您不能将文件指定为卷,这是行不通的。卷是目录。
如果您的配置是不变的并且不希望在容器执行之间发生变化,只需从 mysql/mysql-server:5.7
继承您自己的容器并将新配置 COPY
放入其中:
Dockerfile
FROM mysql/mysql-server:5.7
COPY my.cnf /etc/
并在 docker-compose
中使用您的新图片。
如果配置需要更改,最好使用卷,但您必须在容器启动时手动覆盖它。像这样:
docker-compose.yml
mysql:
image: mysql/mysql-server:5.7
container_name: rucio-mysql
volumes:
- ./mysql-config:/configs
environment:
- MYSQL_ROOT_PASSWORD=pass
- MYSQL_ROOT_HOST=%
command: ["cp", "-f", "/configs/my-master.cnf", "/etc/my.cnf"]
参考 docker 中心部分 "Configuration without a cnf file" 上的官方 MySQL Docker repo,它清楚地提到您可以在基本映像名称后提供配置标志,我发现这更容易 运行 而不是构建 docker 图像。
我的示例 docker 运行 命令将内存使用从默认的 480 mb 优化到仅仅 100 mb
docker 运行 -d -p 3306:3306 -e MYSQL_DATABASE=test -e MYSQL_ROOT_PASSWORD=tooor -e MYSQL_USER= test -e MYSQL_PASSWORD=test -v /mysql:/var/lib/mysql --name mysqldb mysql --table_definition_cache=100 --performance_schema =0 --default-authentication-plugin=mysql_native_password
我无法替换标准 mysql 5.7 容器中的标准 /etc/my.cnf
文件。
我是 运行 一个 mysql 5.7 容器(标准 Docker HUB 映像)。
我想替换 etc/my.cnf
文件以启用主从操作。
我想通过挂载 docker-compose.yml
文件中的卷来实现。
新的my.cnf
应该是:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
# Replication and mirroring settings
server-id = 1
auto_increment_increment = 3
auto_increment_offset = 0
log_bin = /var/log/mysql/log-bin
log_bin_index = /var/log/mysql/log-bin.index
binlog_format = row
expire_logs_days = 10
log_slave_updates
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
在 docker-compose.yml
我有以下几行:
mysql:
image: mysql/mysql-server:5.7
container_name: rucio-mysql
volumes:
- ./mysql-config/my-master.cnf:/etc/my.cnf
environment:
- MYSQL_ROOT_PASSWORD=pass
- MYSQL_ROOT_HOST=%
路径正确,但容器启动并立即退出。
提前致谢,
滑动
您不能将文件指定为卷,这是行不通的。卷是目录。
如果您的配置是不变的并且不希望在容器执行之间发生变化,只需从 mysql/mysql-server:5.7
继承您自己的容器并将新配置 COPY
放入其中:
Dockerfile
FROM mysql/mysql-server:5.7
COPY my.cnf /etc/
并在 docker-compose
中使用您的新图片。
如果配置需要更改,最好使用卷,但您必须在容器启动时手动覆盖它。像这样:
docker-compose.yml
mysql:
image: mysql/mysql-server:5.7
container_name: rucio-mysql
volumes:
- ./mysql-config:/configs
environment:
- MYSQL_ROOT_PASSWORD=pass
- MYSQL_ROOT_HOST=%
command: ["cp", "-f", "/configs/my-master.cnf", "/etc/my.cnf"]
参考 docker 中心部分 "Configuration without a cnf file" 上的官方 MySQL Docker repo,它清楚地提到您可以在基本映像名称后提供配置标志,我发现这更容易 运行 而不是构建 docker 图像。 我的示例 docker 运行 命令将内存使用从默认的 480 mb 优化到仅仅 100 mb
docker 运行 -d -p 3306:3306 -e MYSQL_DATABASE=test -e MYSQL_ROOT_PASSWORD=tooor -e MYSQL_USER= test -e MYSQL_PASSWORD=test -v /mysql:/var/lib/mysql --name mysqldb mysql --table_definition_cache=100 --performance_schema =0 --default-authentication-plugin=mysql_native_password