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 打包的问题就解决了。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
2020-11-03 Postman API 获得文件如何保存
2020-11-03 Postman 提交测试的时候提示 Bad Request