ragflow在CentOS上docker部署时报错dependency failed to start: container ragflow-mysql is unhealthy
报错原因:容器内 MySQL 用户没有权限读取宿主机挂载的文件。我git拉下来ragflow代码时用的是app用户,没有用root用户,导致容器内用户没有权限。解决方法:保证挂载的文件对所有用户可读(chmod 644),目录可进入(chmod 755经验规律:只要容器里的进程不是root,那宿主机挂载的文件就要给 “其他用户” 合理的权限。这样既保证了容器能正常运行,又避免了反复踩坑。✍️后记。
ragflow在CentOS上docker部署时报错dependency failed to start: container ragflow-mysql is unhealthy 的解决方案
一、问题背景
在使用 Docker Compose 部署 Ragflow 的 MySQL 时,我在容器启动日志中遇到了以下报错:
ragflow-mysql | 2025-09-02T00:51:10.786687Z 0 [ERROR] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-000029 - File '/data/application/init.sql' not found (OS errno 13 - Permission denied)
ragflow-mysql | 2025-09-02T00:51:10.786727Z 0 [ERROR] [MY-010455] [Server] Failed to open the bootstrap file /data/application/init.sql
很明显,MySQL 容器在初始化时无法读取我挂载的 init.sql 文件,直接提示 Permission denied。
二、docker-compose.yml 配置
ragflow自带的 docker-compose-base.yml 中是这样挂载的:
services:
mysql:
# mysql:5.7 linux/arm64 image is unavailable.
image: mysql:8.0.39
container_name: ragflow-mysql
env_file: .env
environment:
- MYSQL_ROOT_PASSWORD=${MYSQL_PASSWORD}
- TZ=${TIMEZONE}
command:
--max_connections=1000
--character-set-server=utf8mb4
--collation-server=utf8mb4_unicode_ci
--default-authentication-plugin=mysql_native_password
--tls_version="TLSv1.2,TLSv1.3"
--init-file /data/application/init.sql
--binlog_expire_logs_seconds=604800
ports:
- ${MYSQL_PORT}:3306
volumes:
- mysql_data:/var/lib/mysql
- ./init.sql:/data/application/init.sql
networks:
- ragflow
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-uroot", "-p${MYSQL_PASSWORD}"]
interval: 10s
timeout: 10s
retries: 3
restart: on-failure
其中 init.sql 是我希望在容器启动时自动执行的初始化脚本。
三、排查思路
1. 宿主机文件权限
进入宿主机,查看文件权限:
ls -l ./init.sql
结果:
-rw-r----- 1 app app 53 Feb 26 2025 ./init.sql
可以看到:
- 属主:
app - 属组:
app - 权限:
640(属主可读写,属组可读,其他用户无权限)
2. 容器内 MySQL 的运行用户
官方 MySQL Docker 镜像默认是以 mysql 用户(UID=999)运行的,
它既不是宿主机的 root,也不是 app 用户。
所以在容器内访问这个文件时,就相当于 “其他用户” → 没权限读取。
这就是报错 OS errno 13 - Permission denied 的根因。
四、解决方案
只需要把文件权限改成所有用户可读即可:
chmod 644 ./init.sql
再次确认:
ls -l ./init.sql
结果:
-rw-r--r-- 1 app app 53 Feb 26 2025 ./init.sql
此时容器再启动,MySQL 就能顺利读取并执行 init.sql 脚本。
六、总结
- 报错原因:容器内 MySQL 用户没有权限读取宿主机挂载的文件。我git拉下来ragflow代码时用的是app用户,没有用root用户,导致容器内用户没有权限。
- 解决方法:保证挂载的文件对所有用户可读(
chmod 644),目录可进入(chmod 755)。 - 经验规律:只要容器里的进程不是
root,那宿主机挂载的文件就要给 “其他用户” 合理的权限。
这样既保证了容器能正常运行,又避免了反复踩坑。
✍️ 后记:
这类权限问题在 Docker 部署中非常常见,尤其是 MySQL、PostgreSQL、Nginx 这类默认用非 root 用户跑的容器。建议大家在调试挂载时,优先从 宿主机文件权限 入手!
更多推荐




所有评论(0)