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 打包的问题就解决了。

https://www.ossez.com/t/jenkins-docker-host/14191

未经允许不得转载:木盒主机 » Jenkins 构建的时候提示 DOCKER_HOST 错误

赞 (0)

相关推荐

    暂无内容!