背景

使用docker-compose启动mysql容器的时候容器状态一直在重启

[root@localhost-203-root-all mysql_8.0.25]# docker-compose ps
    Name                 Command               State      Ports
---------------------------------------------------------------
mysql_8.0.25   docker-entrypoint.sh mysqld   Restarting  

查看日志提示/dev/null: Permission denied

mysql_8.0.25 | 	/usr/local/bin/docker-entrypoint.sh: line 92: /dev/null: Permission denied
mysql_8.0.25 | 2022-02-22 15:55:08+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
mysql_8.0.25 | 2022-02-22 15:55:08+08:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql_8.0.25 | 2022-02-22 15:55:08+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
mysql_8.0.25 | 2022-02-22 15:55:08+08:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
mysql_8.0.25 | 	command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.O6IeztzNrT
mysql_8.0.25 | 	/usr/local/bin/docker-entrypoint.sh: line 92: /dev/null: Permission denied

刚开始以为是配置文件出问题了,仔细检查配置文件,后面改到只剩下以下配置

[client]
default-character-set = utf8
[mysqld]
server-id=2
port = 3306
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_ci
max_connections = 1024 # 最大连接数量
max_allowed_packet = 64M
lower_case_table_names = 1 # 关闭大小写敏感
innodb_buffer_pool_size = 256M
join_buffer_size = 256M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
symbolic-links=0
log_error=/var/log/mysql/mysqld.log
pid-file=/var/log/mysql/mysqld.pid
slow_query_log = on
slow_query_log_file = /var/log/mysql/slow.log
long_query_time  = 1000.000000
log_bin=/var/log/mysql/binlog

重启后仍然同样的症状,又怀疑是mysql数据损坏,将data目录清除掉,重新创建容器,仍然是一样的症状,并且,data目录并没有生成任何mysql相关文件,docker-compose.yml文件

version: '3.7'
services:
  mysql:
    hostname: mysql
    restart: always
    container_name: mysql_8.0.25
    image: mysql:8.0.25
    env_file:
      - ./env/mysql.env
    environment:
      - TZ=Asia/Shanghai
    ports:
      - '23306:3306'
    privileged: true
    volumes:
      - /deploy/sorts/mysql_8.0.25/conf/my.cnf:/etc/mysql/my.cnf
      - /deploy/sorts/mysql_8.0.25/data/mysql:/var/lib/mysql
      - /deploy/sorts/mysql_8.0.25/data/mysql-files:/var/lib/mysql-files
      - /deploy/sorts/mysql_8.0.25/log/mysql:/var/log/mysql

又怀疑是镜像问题,使用docker run直接运行,发现可以运行

docker run -itd -e "MYSQL_ROOT_PASSWORD=123456" mysql:8.0.25

又怀疑docker环境是不是坏了,将docker环境重新安装了下,并且重启了docker,仍然不行 无奈之下,将问题截图发到运维群,经群大佬提示,发现是/dev/null文件有问题,我才想起,以前做测试的时候将这个文件删除了,然后又手工创建了这个文件,于是对比了下这个主机的这个文件和别的主机的这个文件的属性,发现权限不一样

[root@localhost-203-root-all mysql_8.0.25]# ls -l /dev/null 
crw-r--r-- 1 root root 1, 3 Jan 20 13:40 /dev/null

修改了权限后就可以正常启动了

chmod o+w /dev/null
chmod g+w /dev/null