環境
騰訊的 TencentOS Server 4.4 服務器系統
Linux app 6.6.92-34.1.tl4.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 25 14:33:47 CST 2025 x86_64 x86_64 x86_64 GNU/Linux
docker使用的是yum安裝的版本
[root@app ~]# docker version
Client:Version: 28.0.1-20241223130549-3b49debAPI version: 1.48Go version: go1.24.4Git commit: 3b49debBuilt: Mon Aug 11 09:03:23 2025OS/Arch: linux/amd64Context: defaultServer:Engine:Version: 28.0.1API version: 1.48 (minimum version 1.24)Go version: go1.24.2Git commit: %{_gitcommit_engine}Built: Thu Jun 12 10:00:10 2025OS/Arch: linux/amd64Experimental: falsecontainerd:Version: 1.7.27GitCommit: runc:Version: 1.1.14GitCommit: docker-init:Version: 0.19.0GitCommit: de40ad0
問題現象
docker創建的mysql 5.7.44容器(官方鏡像)無法正常啟動,隔幾秒就重啟
docker logs mysql 打印:
2025-08-27 15:45:46+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2025-08-27 15:46:01+08:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check configcommand was: mysqld --verbose --help --log-bin-index=/tmp/tmp.RBl3Hbmt6u2025-08-27 15:46:15+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2025-08-27 15:46:26+08:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check configcommand was: mysqld --verbose --help --log-bin-index=/tmp/tmp.hZa5kwNZnP2025-08-27 15:46:28+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2025-08-27 15:46:37+08:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check configcommand was: mysqld --verbose --help --log-bin-index=/tmp/tmp.6eeHXfFfzH2025-08-27 15:46:39+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
2025-08-27 15:46:48+08:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check configcommand was: mysqld --verbose --help --log-bin-index=/tmp/tmp.lvQBb4Rtwb
進入到容器手動運行mysqld命令也沒有有用的信息,會在光標卡一段時間后提示killed。
查找資料
很幸運谷歌到了一個issues:官方docker github里的issuse
里面的回復:
Hello,I know this post is old, nevertheless, for those who come across it in the future like me, this solution allows resolving the issue without intervening in the host system configuration:---
version: '3.6'
services:mysql:image: mysql:5.7ulimits:nofile: # Fix memory leak issue on some systems when LimitCORE=infinity (containerd)soft: 1048576hard: 1048576
This is a configuration for Compose (Docker plugin). However, you can use the equivalent, such as docker run mysql:5.7 --ulimit nofile=1048576:1048576.For your information, I encountered a similar issue with the library/elasticsearch:2.4-alpine image.I use Fedora Workstation Silverblue 39
我原來運行的命令:
docker run -d --name mysql \
-v /app/mysql/binlogs:/ava_app/mysql/binlogs \
-v /app/mysql/conf:/etc/mysql \
-v /app/mysql/logs:/var/log/mysql \
-v /data/upload:/ava_data/upload \
-v /etc/localtime:/etc/localtime:ro \
-v /app/timezone:/etc/timezone:ro \
-e "MYSQL_ROOT_PASSWORD=xxxxxxxxxxxx" \
--restart always --network=host mysql:5.7.44
根據上面方法改進的命令:
# 加入 --ulimit nofile=1048576:1048576
docker run -d --ulimit nofile=1048576:1048576 --name mysql \
-v /app/mysql/binlogs:/ava_app/mysql/binlogs \
-v /app/mysql/conf:/etc/mysql \
-v /app/mysql/logs:/var/log/mysql \
-v /data/upload:/ava_data/upload \
-v /etc/localtime:/etc/localtime:ro \
-v /app/timezone:/etc/timezone:ro \
-e "MYSQL_ROOT_PASSWORD=xxxxxxxxxxxx" \
--restart always --network=host mysql:5.7.44
解決
后續根據“ docker mysql ulimit ”關鍵詞查到的幾個文章
https://cloud.tencent.com/developer/article/2448486
https://blog.chenwx.top/p/docker-mysql-event1.html
https://www.cnblogs.com/littlezt/p/16252678.html