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

查看:138
本文介绍了Jenkins:无法连接到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

+ 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 is 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: sorry, you must have a tty to run 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

现在是时候重新加载并重新启动Docker守护程序了

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

systemctl daemon-reload
systemctl restart docker

然后我重新启动了jenkins,并且能够在我的jenkins作业中以jenkins用户的身份执行docker命令

Then I restarted jenkins and I was able to perform docker commands as jenkins user in my jenkins jobs

sudo service jenkins restart

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

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