Jenkins 构建的时候提示 DOCKER_HOST 错误

我们在使用 Jenkins 构建我们的一个 Docker 项目的时候提示:

[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.40.2:build (default) on project api: Execution default of goal io.fabric8:docker-maven-plugin:0.40.2:build failed: No <dockerHost> given, no DOCKER_HOST environment variable, no read/writable '/var/run/docker.sock' or '//./pipe/docker_engine' and no external provider like Docker machine configured -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:

通过日志我们了解到上面的问题就是 Jenkins 没有办法调用 Docker 的构建命令。

问题和解决

我们尝试了很多种方法来解决这个问题。

包括有重新安装 Docker,重新写脚本等等,都发现没有办法解决。

然后我们在下载的 Git 代码中直接使用 Root 账号进行编译,发现是没有问题的。

这个就让我想到,有没有可能是因为 Jenkins 的用户没有访问 Docker 的权限

因为 Jenkins 的编译是在 Jenkins 自己这个账号下运行的的。

随后我们运行了下面 2 个命令。

sudo gpasswd -a jenkins docker

sudo usermod -a -G docker jenkins

上面命令运行后的输出如下:

[root@devops-norctx-com Usvisatrack-Api-Service]# sudo gpasswd -a jenkins docker
Adding user jenkins to group docker
[root@devops-norctx-com Usvisatrack-Api-Service]# sudo usermod -a -G docker jenkins

简单来说,上面 2 个命令执行的结果就是吧 Jenkins 这个用户加到 Docker 这个用户组里面。

在完成上面的配置后,重启 Jenkins。

然后再进行编译,我们发现提示没有办法执行 Docker 打包的问题就解决了。

Jenkins 构建的时候提示 DOCKER_HOST 错误 - DevOps - OSSEZ

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HoneyMoose

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值