我无法替换标准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=%
路径正确,但是容器已启动并立即退出。
预先感谢
滑动
答案 0 :(得分:1)
您不能将文件指定为卷,这是行不通的。卷是目录。
如果您的配置是恒定的,并且预计在容器执行之间不会更改,则只需从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"]
答案 1 :(得分:0)
参考dockerhub上的官方MySQL Docker repo部分“没有cnf文件的配置”,它明确提到您可以在基本映像名称之后提供配置标志,我发现它比运行docker映像更容易运行。 我的示例docker run命令可将内存使用从默认的480 mb优化为仅100 mb
docker run -d -p 3306:3306 -e MYSQL_DATABASE = test -e MYSQL_ROOT_PASSWORD =太-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