当前位置:   article > 正文

ubuntu 启动 docker 容器立刻退出Exited (1) ? seconds ago_docker ubuntu闪退

docker ubuntu闪退

问题描述

docker 启动容器后立刻退出 Exited (1) ? seconds ago

c7640d82acb4   mysql:8.2.0   "docker-entrypoint.s…"   8 minutes ago   Exited (1) 2 minutes ago             mysql
root@ping-ubuntu:/# docker run -p 3306:3306 --name mysql5 -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7
65c2097b734e487e392d68f779f30912881146ac727fc54e427c9b8d4fac3641

root@ping-ubuntu:/# docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS                     PORTS     NAMES
65c2097b734e   mysql:5.7     "docker-entrypoint.s…"   8 seconds ago   Exited (1) 8 seconds ago             mysql5
c7640d82acb4   mysql:8.2.0   "docker-entrypoint.s…"   9 minutes ago   Exited (1) 3 minutes ago             mysql

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

原因分析:

检查日志,觉得可能是没有给docker读取配置文件的权限
mysqld: Can’t read dir of ‘/etc/mysql/conf.d/’ (OS errno 2 - No such file or directory)

2023-12-16 09:44:06+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.2.0-1.el8 started.
2023-12-16 09:44:06+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
	command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.m4atmHpc15
	mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory)
mysqld: [ERROR] Stopped processing the 'includedir' directive in file /etc/my.cnf at line 36.
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
2023-12-16 09:50:16+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.2.0-1.el8 started.
2023-12-16 09:50:16+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
	command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.MxRUaLY7uH
	mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory)
mysqld: [ERROR] Stopped processing the 'includedir' directive in file /etc/my.cnf at line 36.
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

步骤1:

打开配置文件所在目录的读写权限

 	chmod 777 mydata -R 
  • 1

发现还是不行,又仔细看了日志说明:

mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory)
  • 1

原来是没有conf.d这个文件/文件夹。

步骤2:

查看 官网说明,/etc/my.cnf里面有以下两行,大意就是my.cnf这个配置文件又包含了/etc/mysql/conf.d/和/etc/mysql/mysql.conf.d/目录下的配置文件。官网的mysql配置文件里包含了以下两行,说明是需要这两个文件夹的

!includedir /etc/mysql/conf.d/     
!includedir /etc/mysql/mysql.conf.d/
  • 1
  • 2

所以我们仅仅只需在主机conf文件夹下,建立conf.d和mysql.conf.d两个文件夹,再运行创建MySQL的容器即可
cd /mydata/mysql/conf mkdir mysql.conf.d

	mkdir conf.d
	mkdir mysql.conf.d
  • 1
  • 2

步骤4:

COLLATION ‘utf8_unicode_ci’ is not valid for CHARACTER SET ‘utf8mb4’

root@ping-ubuntu:/mydata/mysql/conf# docker logs 39ff7c04bb86
2023-12-16 11:38:50+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.2.0-1.el8 started.
2023-12-16 11:38:50+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
	command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.ry7DK0Cb3K
	2023-12-16T11:38:50.898161Z 0 [ERROR] [MY-010936] [Server] COLLATION 'utf8_unicode_ci' is not valid for CHARACTER SET 'utf8mb4'
2023-12-16T11:38:50.899268Z 0 [ERROR] [MY-010119] [Server] Aborting

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

说明如下设置的字符集编码内容是有问题

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci' init_connect='SET NAMES utf8' character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

修改后如下:

[client]
default_character_set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation_server = utf8_general_ci
character_set_server = utf8
skip-character-set-client-handshake
skip-name-resolve

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

结束:

删除之前的容器,新建一个容器

docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql:8.2.0

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

docker ps -a 查看

root@ping-ubuntu:/mydata/mysql/conf# docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS         PORTS                                                  NAMES
cd5e013d8cd5   mysql:8.2.0   "docker-entrypoint.s…"   9 seconds ago   Up 8 seconds   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql


  • 1
  • 2
  • 3
  • 4
  • 5

撒花

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/511579
推荐阅读
相关标签