Jenkins 构建的时候提示 DOCKER_HOST 错误
2023-06-13 09:14:32 时间
我们在使用 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自动部署微服务与springboot项目【入门到精通-待更新】
- k8s+jenkins自动部署前后台
- CentOS_Docker_Nginx_Node_Jenkins
- Docker查看本地所有的镜像命令(docker images)
- Veinmind 在 Jenkins 的0部署成本自动化扫描方案
- 解决jenkins打包时不能及时更新到最新代码的问题
- 「 【Docker】用docker运行2048小游戏(玩转docker) 」
- 「 【Docker】利用宝塔docker管理器搭建为知笔记(docker安装为知笔记) 」
- 软件测试|一键搞定centos7的docker+selenium+appium+jenkins+android_app源码打包成apk的环境搭建
- jenkins报错403的解决方案
- 【Docker 系列】docker 学习 一,Docker的安装使用及Docker的基本工作原理
- Jenkins安装
- Jenkins + Docker 一键自动化部署 Java Spring Boot 应用最简流程
- docker从Abp到MySQL,使用Docker快速部署(abpmysql)
- jenkins服务器部署扫描器:sonar-scanner