As an argument to the container command:
docker run -it -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.7 --max-allowed-packet=67108864
See "Configuration without a cnf file" at https://hub.docker.com/_/mysql/, copied here for posterity:
Configuration without a cnf file Many configuration options can be
passed as flags to mysqld. This will give you the flexibility to
customize the container without needing a cnf file. For example, if
you want to change the default encoding and collation for all tables
to use UTF-8 (utf8mb4) just run the following:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
If you would like to see a complete list of available options, just run:
$ docker run -it --rm mysql:tag --verbose --help
When using docker-compose
(as asked in the comments), add a command
key with the arguments:
version: "3"
services:
data:
image: "mysql:5.7.20"
command: --max_allowed_packet=32505856 # Set max_allowed_packet to 256M (or any other value)
environment:
- MYSQL_ROOT_PASSWORD=password
- MYSQL_DATABASE=db
- MYSQL_USER=user
- MYSQL_PASSWORD=user_password