背景:
项目使用了mysql5.7的官方镜像,配置启动log_bin不生效。
解决方法
一般情况下都是修改 my.cnf下的配置。但docker有点不一样
查看 my.cnf配置:
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
引用了mysql.conf.d下的配置,查看了mysqld.cnf内容说明
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
这个就是我们最终需要要改的,但docker修改配置需要重启服务,我们在rancher上集成的,每次重启相当于重新部署,配置还是会被初始化。最后使用dockerfile的方式构建:
FROM mysql:5.7
COPY mysqld.cnf /etc/mysql/mysql.conf.d/
mysqld.cnf内容:
#
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address = 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#以下是启动log-bin的配置
log-bin = binlog
server-id=1
binlog-format = ROW
binlog_rows_query_log_events = off
最后docker build 一下就可以构建已经修改了配置的镜像,然后自己拉取自己生成的镜像就可以了。
官方镜像:
自己构建后的镜像: