docker 启动数据库异常
1.docker启动数据库时出现异常,爆出这样的错误:
首先运行docker
[root@zpjeck ~]# docker run -d mysql
238aedcdc9c42517299fefe6534ed6176d0f8e3e072f7f56138e286f4d671d4f
紧接着查看docker是否启动成功:
[root@zpjeck ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
238aedcdc9c4 mysql "docker-entrypoint..." 21 seconds ago Exited (1) 20 seconds ago relaxed_khorana
2.查看错误日志
[root@zpjeck ~]# docker logs 238aedcdc9c4
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
3.根据官方文档显示 启动时需要指定密码
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
... where some-mysql
is the name you want to assign to your container, my-secret-pw
is the password to be set for the MySQL root user and tag
is the tag specifying the MySQL version you want. See the list above for relevant tags.
4.正确的启动方式:
[root@zpjeck ~]# docker run --name mysql_01 -e MYSQL_ROOT_PASSWORD=123456 -d mysql
e06e25408eb6d623bc166bed97996445f6db32e4397a163920828a6ad7aed31b
[root@zpjeck ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e06e25408eb6 mysql "docker-entrypoint..." 7 seconds ago Up 6 seconds 3306/tcp, 33060/tcp mysql_01
docker中启动数据就算成功了
转自:https://blog.csdn.net/ZPJeck/article/details/83987179