I am using Docker for mysql. Need to set the system variables such as max_allowed_packet, character_set_server and collation-server of mysql in the Dockerfile. I tried with the below commands providing in the Dockerfile. but its not working.
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"]
Build command:
sudo docker build -t mysqltest:1 .
Run command:
sudo docker run -p 3306:3306 -restart=always -d mysqltest:1
There are several approaches, this is one:
CMD ["--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci", "--max-allowed-packet=1073741824"]
As an alternative you can put a custom config file in /etc/mysql/conf.d
custom-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/
More here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With