使用Docker executor运行GitLab CI/CD需本地启动Docker吗?报错求解
GitLab CI/CD Docker Executor 问题解答
问题描述
当使用Docker executor运行GitLab CI/CD时,本地系统是否必须安装并运行Docker?本地未启动Docker时,CI/CD执行出现如下报错,若并非必须,求解决办法。
报错信息:
Running with gitlab-runner 15.4.0 (43b2dc3d) on runner3-dockerlatest pbSCcuw5 Preparing the "docker" executor 00:09 ERROR: Failed to remove network for build ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:863:0s) Will be retried in 3s ... ERROR: Failed to remove network for build ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:863:0s) Will be retried in 3s ... ERROR: Failed to remove network for build ERROR: Preparation failed: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:863:0s) Will be retried in 3s ... ERROR: Job failed (system failure): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:863:0s)
解答
核心结论
使用Docker executor时,运行GitLab Runner的系统(不管是本地还是远程服务器)必须安装并运行Docker daemon。Docker executor的工作逻辑就是调用本地Docker守护进程来创建任务所需的容器、网络等资源,你遇到的报错就是因为Runner找不到可用的Docker daemon。
无需本地Docker的替代方案
如果不想依赖本地Docker,可以更换GitLab Runner的executor类型:
- Shell executor:直接在Runner所在系统的shell环境执行任务,不需要Docker,但任务会直接操作宿主系统环境,隔离性较差。
- Kubernetes executor:将CI/CD任务调度到Kubernetes集群中运行,由集群负责容器管理,此时Runner节点无需安装Docker(集群节点需要容器运行时,但不用你在本地维护)。
- VirtualBox/VMware executor:通过虚拟机隔离任务环境,不需要Docker支持,但需要提前配置好对应的虚拟化工具。
Docker executor报错的解决办法
如果坚持使用Docker executor,只需启动本地Docker daemon即可:
- Linux系统:执行命令
sudo systemctl start docker,要设置开机自动启动可以用sudo systemctl enable docker。 - Windows/macOS:打开Docker Desktop应用,等待状态栏图标显示就绪状态即可。
内容的提问来源于stack exchange,提问作者Thor
相关产品推荐
相关产品推荐

