Docker Compose 启动失败问题解决方案
错误描述
执行 docker compose up -d
时出现以下错误:
[+] Running 9/9
✘ api Error context canceled 15.1s
✘ redis Error Get "https://registry-1.docker.io/v2/": context deadline exceeded (Client.Timeout exceeded while awaiting headers) 15.1s
(其他服务类似错误...)
Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded
核心问题:Docker客户端访问注册中心超时,可能原因包括:
- 网络连接问题
- Docker服务异常
- 镜像源不可用
解决方法
1. 基础检查
1.1 网络连通性测试
ping www.baidu.com # 确认基础网络正常
1.2 Docker服务状态
systemctl status docker # 确认服务处于active (running)状态
2. 镜像源优化(推荐方案)
2.1 配置国内镜像源
编辑 /etc/docker/daemon.json
:
{
"registry-mirrors" : ["https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc",
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://dockerproxy.com",
"https://gst6rzl9.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"http://mirrors.ustc.edu.cn/",
"https://mirrors.tuna.tsinghua.edu.cn/",
"http://mirrors.sohu.com/"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
],
"debug": true,
"experimental": false
}
2.2 应用配置
sudo systemctl daemon-reload
sudo systemctl restart docker
docker info # 验证配置生效
3. 进阶排查
- 镜像版本问题:检查
docker-compose.yml
中的镜像标签是否有效(如langgenius/dify-api:0.15.3
) - 资源限制:确保系统有足够内存/CPU资源
- 代理设置:若使用企业网络,需配置代理服务器
效果验证
重新执行启动命令:
docker compose up -d # 成功启动后无错误输出
注意:若问题持续,建议检查防火墙规则或尝试手动拉取镜像(如
docker pull redis:latest
)