我正在使用Docker for mysql。需要在Dockerfile中设置系统变量,如max_allowed_packet,character_set_server和mysql的collation-server。我尝试使用Dockerfile中提供的以下命令。但它不起作用。
Dockerfile:
FROM mysql:latest
VOLUME /opt/data:/var/lib/mysql
ENV MYSQL_ROOT_PASSWORD password
RUN sed -i 's/^max_allowed_packet.*/max_allowed_packet = 1073741824/' /etc/mysql/my.cnf
RUN sed -i "/\[mysqld]/a character-set-server=utf8mb4" /etc/mysql/my.cnf
RUN sed -i 's/^collation-server.*/collation-server = utf8mb4_unicode_ci/' /etc/mysql/my.cnf
CMD ["mysqld"]
构建命令:
sudo docker build -t mysqltest:1 .
运行命令:
sudo docker run -p 3306:3306 -restart=always -d mysqltest:1
答案 0 :(得分:6)
有几种方法,一种是:
CMD ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci", "--max-allowed-packet=1073741824"]
作为替代方案,您可以在/etc/mysql/conf.d
定制mysql.cnf:
[mysqld]
max_allowed_packet = 1073741824
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
Dockerfile:
FROM mysql:latest
COPY ./custom-mysql.cnf /etc/mysql/conf.d/
更多here