如何覆盖标准MySQL 5.7容器配置



我不能在标准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.7COPY新配置继承您自己的容器:

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"]

涉及Dockerhub官方docker repo"没有CNF文件的配置",它清楚地提到您可以在基本图像名称之后提供配置标志,我发现运行它更容易运行而不是构建码头图像。我的示例Docker Run命令以优化从默认480 MB到仅100 MB

的内存使用量table_definition_cache = 100 - performance_schema = 0 -default-authentication-plugin = mysql_native_password

最新更新