如何覆盖标准MySQL5.7容器配置

ux6nzvsh  于 2021-06-15  发布在  Mysql
关注(0)|答案(2)|浏览(349)

我不能代替标准 /etc/my.cnf 标准MySQL5.7容器中的文件。
我正在运行一个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=%

路径是正确的,但是容器立即启动并退出。
提前谢谢,

brtdzjyr

brtdzjyr1#

不能将文件指定为卷,这样做行不通。卷是目录。
如果您的配置是常量,并且不希望在容器执行之间发生更改,只需从中继承您自己的容器即可 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"]
wa7juj8i

wa7juj8i2#

参考官方mysql docker repo on dockerhub部分“没有cnf文件的配置”,它清楚地提到,可以在基本映像名称之后提供配置标志,我发现运行起来比构建docker映像更容易。我的示例docker运行命令将内存使用率从默认的480MB优化到仅100MB
docker run-d-p 3306:3306-e mysql\u database=test-e mysql\u root\u password=tooor-e mysql\u user=test-e mysql\u password=test-v/mysql:/var/lib/mysql--name mysqldb mysql--table\u definition\u cache=100--performance\u schema=0--default authentication plugin mysql\u native\u password

相关问题