简体   繁体   中英

Build docker container for Mysql 8.0 fail

I need create a docker container for several projects tha use Mysql 8.0 with PHP 7.3

I like create it, because I need modify mysql startup configuration

For this I create

Dockerfile

FROM mysql:8.0

COPY mysqld_charset.cnf /etc/mysql/conf.d/mysqld_charset.cnf

ENV MYSQL_ROOT_PASSWORD="123456"

mysqld_charset.cnf

[mysqld]
default-authentication-plugin = mysql_native_password
collation-server = utf8mb4_general_ci
character-set-server = utf8mb4

License and readme files.

Execute

$ docker build --no-cache -t mysql8_legacy_password .                                                                     
Sending build context to Docker daemon  14.85kB
Step 1/3 : FROM mysql:8.0
 ---> 62a9f311b99c
Step 2/3 : COPY mysqld_charset.cnf /etc/mysql/conf.d/mysqld_charset.cnf
 ---> 0e21143ae822
Step 3/3 : ENV MYSQL_ROOT_PASSWORD="123456"
 ---> Running in a8d350dbd651
Removing intermediate container a8d350dbd651
 ---> 7dd66b27be00
Successfully built 7dd66b27be00
Successfully tagged mysql8_legacy_password:latest

$  docker run --name mysql8_legacy_password  -it mysql:8.0                                                                
error: database is uninitialized and password option is not specified 
  You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD

The issue is in the run command.

docker run --name mysql8_legacy_password -it mysql:8.0

You are trying to start a container from mysql:8.0 image in which no env has been setup.

The last argument of the docker run command should be the image name. Since you have tagged your image as mysql8_legacy_password , this should work:

docker run --name container_name -it mysql8_legacy_password

docker run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM