1.问题描述
docker启动mysql因为配置文件报错,导致容器启动不了。

2.查看docker日志

docker logs 934d3ecaac051d9cad3

报错如下:

2020-07-27T12:55:46.949838Z 0 [Note] Shutting down plugin 'binlog'
2020-07-27T12:55:46.950677Z 0 [Note] mysqld: Shutdown complete

2020-07-27 12:55:47+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
2020-07-27 12:55:47+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
	command was: mysqld --verbose --help
	mysqld: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 26!
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
2020-07-27 12:57:28+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
2020-07-27 12:57:28+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
	command was: mysqld --verbose --help
	mysqld: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 26!

3.问题原因
因为docker中的mysql的配置文件错误导致,dokcer容器启动不了。

4.解决方案
a.通过cp命令将docker容器里面的错误的配置文件复制到宿主机,命令:

docker cp 934d3ecaac051d9cad356:/etc/mysql/mysql.cnf /usr/my.cnf

b.将复制出来的配置文件修改正确

c.通过cp命令将宿主机正确的配置文件复制到docker容器中,命令:

docker cp my.cnf 934d3ecaac051d9cad356:/etc/mysql/mysql.cnf 

d.重启docker容器

5.结果
容器启动成功:

[root@iZbp1e9mxelwe7pwimpw8sZ usr]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
934d3ecaac05        mysql:5.7-2         "docker-entrypoint.s…"   2 months ago        Up 9 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   mysql5.7-2

6.文章参考链接
a. https://blog.csdn.net/hecr_mingong/article/details/105924976
b. https://blog.csdn.net/chen649053473/article/details/104755334

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐