詹金斯:无法连接到 Docker 守护进程 [英] Jenkins: Can't connect to Docker daemon

查看:47
本文介绍了詹金斯:无法连接到 Docker 守护进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 CentOS 机器上运行 Jenkins 和 Docker.我有一个 Jenkins 工作,它提取一个 Github 存储库并构建一个 Docker 映像.当我尝试运行作业时出现错误:

I am running Jenkins and Docker on a CentOS machine. I have a Jenkins job that pulls a Github repo and builds a Docker image. When I try running the job I get the error:

+ docker build -t myProject .
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Build step 'Execute shell' marked build as failure
Finished: FAILURE

即使我通过 sudo usermod -aG docker jenkins 将 jenkins 添加到我的 docker 用户组并重新启动了我的机器,也会出现这个问题.我该如何解决这个问题?

This problem occurs even though I have added jenkins to my docker usergroup via sudo usermod -aG docker jenkins and restarted my machine. How do I fix this?

顺便说一句,如果尝试将命令更改为 sudo docker build -t myProject 我只是收到错误 sudo:抱歉,你必须有一个 tty 才能运行 sudo

By the way, if try changing the command to sudo docker build -t myProject . I just get the error sudo: sorry, you must have a tty to run sudo

推荐答案

安装 Jenkins 和 Docker 后.将 jenkins 用户添加到 dockergroup(就像你一样)

After the installation of Jenkins and Docker. Add jenkins user to dockergroup (like you did)

sudo gpasswd -a jenkins docker

编辑以下文件

vi /usr/lib/systemd/system/docker.service

并编辑此规则以公开 API :

And edit this rule to expose the API :

ExecStart=/usr/bin/docker daemon -H unix:// -H tcp://localhost:2375

不要用 ExecStart 创建新行,只需在现有行的末尾添加命令即可.

Do not create a new line with ExecStart, simply add the commands at the end of the existing line.

现在是时候重新加载并重启你的 Docker 守护进程

Now it's time to reload and restart your Docker daemon

systemctl daemon-reload
systemctl restart docker

然后重新启动 jenkins,您应该可以在 jenkins 作业中以 jenkins 用户身份执行 docker 命令

Then restart jenkins, you should be able to perform docker commands as jenkins user in your jenkins jobs

sudo service jenkins restart

这篇关于詹金斯:无法连接到 Docker 守护进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆