FROM mysql:8.0.20 ENV MYSQL_USER root ENV MYSQL_PASSWORD root ENV MYSQL_ROOT_PASSWORD root ENV MYSQL_DATABASE test ENV MYSQL_HOST 127.0.0.1 ENV MYSQL_PORT 3306
と言う設定で MySQL のコンテナを起動したところ
$ docker run --name $ContainerName -it --rm -p 3306:3306 $ImageName 2020-06-14 14:26:53+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started. 2020-06-14 14:26:53+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2020-06-14 14:26:53+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started. 2020-06-14 14:26:53+00:00 [Note] [Entrypoint]: Initializing database files 2020-06-14T14:26:53.845977Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release. 2020-06-14T14:26:53.846034Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 45 2020-06-14T14:26:53.851083Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2020-06-14T14:26:54.201911Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2020-06-14T14:26:55.253759Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. 2020-06-14 14:26:57+00:00 [Note] [Entrypoint]: Database files initialized 2020-06-14 14:26:57+00:00 [Note] [Entrypoint]: Starting temporary server mysqld will log errors to /var/lib/mysql/31fa027d7c28.err mysqld is running as pid 94 2020-06-14 14:26:57+00:00 [Note] [Entrypoint]: Temporary server started. Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it. 2020-06-14 14:27:00+00:00 [Note] [Entrypoint]: Creating user root ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'
と言うエラーが出てコンテナが起動できませんでした。
調べたら Dockerfile で MySQL の root ユーザー名を指定していたので MySQL のコンテナを起動する時に root ユーザーを作れないエラーでした。。。
According to this github issue, the problem is setting MYSQL_USER to root. It will fail to create the second user 'root'@'%' since it will already exist in the users table.
MYSQL_USER
に指定するユーザー名を root 以外にしたら無事起動できました。