centos7升级docker1.13到docker26.1.4解决mysql8.0容器起不来

centos7升级docker1.13到docker26.1.4解决mysql8.0容器起不来
linux_centos
内容目录

环境

CentOS Linux release 7.9.2009 (Core)
Bit:64 Mem:15881M Core:4
Linux 3.10.0-1160.102.1.el7.x86_64 #1 SMP Tue Oct 17 15:42:21 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-210.git7d71120.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      7d71120/1.13.1
 Built:           Wed Mar 20 16:04:34 2024
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-210.git7d71120.el7.centos.x86_64
 Go version:      go1.10.3
 Git commit:      7d71120/1.13.1
 Built:           Wed Mar 20 16:04:34 2024
 OS/Arch:         linux/amd64
 Experimental:    false

需求

services:
  mysql:
    image: mysql:8.0
    container_name: mysql8
    restart: always
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_ROOT_HOST: '%'
    volumes:
      - ./data:/var/lib/mysql
      - ./my.cnf:/etc/my.cnf
    command: --default-authentication-plugin=mysql_native_password

docker-compose启动mysql8.0容器一直报错

2025-08-22 00:37:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.42-1.el9 started.
2025-08-22 00:37:25+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2025-08-22 00:37:25+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.42-1.el9 started.
2025-08-22 00:37:25+00:00 [Note] [Entrypoint]: Initializing database files
2025-08-22T00:37:25.667745Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2025-08-22T00:37:25.667795Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2025-08-22T00:37:25.667905Z 0 [Warning] [MY-010918] [Server] 'default_authentication_plugin' is deprecated and will be removed in a future release. Please use authentication_policy instead.
2025-08-22T00:37:25.667933Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.42) initializing of server in progress as process 81
2025-08-22T00:37:25.669846Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2025-08-22T00:37:25.669860Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2025-08-22T00:37:25.669961Z 0 [ERROR] [MY-010119] [Server] Aborting
2025-08-22T00:37:25.670215Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.42)  MySQL Community Server - GPL.

原因

Docker 1.13.1 版本太老了,几乎无法直接运行官方 MySQL 8 镜像。

  1. API 与功能支持不足

    • Docker 1.13 的 runtime、卷挂载、网络驱动、存储驱动等功能太老,MySQL 8 容器在启动、初始化数据目录时可能会失败。
  2. 依赖库和系统兼容性

    • 官方 MySQL 8 镜像可能使用了较新的 glibc / libssl 等库,而 Docker 1.13 对这些新镜像兼容性差,会导致容器启动报错或不停重启。

解决方案

# 卸载旧版本
yum remove docker docker-client docker-common docker-engine

# 安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2

# 添加 Docker CE 仓库
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

# 安装最新稳定版 Docker
yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

# 启动 Docker
systemctl enable docker
systemctl start docker

# 验证版本
docker version

docker-compose启动完美解决

docker-compose up -d

新环境还是推荐ubuntu24.04,支持到2036,组件也新,排查狗屁倒灶的版本问题太蛋疼了

Comments

No comments yet. Why don’t you start the discussion?

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注