# Jenkins 构建的时候提示 DOCKER\_HOST 错误

**URL:** <https://www.isharkfly.com/t/jenkins-docker-host/14191>\
**Category:** DevOps\
**Tags:** docker, jenkins\
**Created:** [November 3, 2022, 10:34am UTC](https://www.isharkfly.com/t/jenkins-docker-host/14191 "2022-11-03T10:34:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [November 3, 2022, 10:34am UTC](https://www.isharkfly.com/t/jenkins-docker-host/14191/1 "2022-11-03T10:34:27Z")

</div>

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

```auto
[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:

```

 ![63554849bb82881f8e22dcf01a0094946f2910ff_2_690x288](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/3X/e/3/e35f7905e577d66a774a7d8e35f360d47625c69a.png)

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

## 问题和解决

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

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

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

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

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

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

```auto
sudo gpasswd -a jenkins docker

sudo usermod -a -G docker jenkins

```

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

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

---

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [November 3, 2022, 10:36am UTC](https://www.isharkfly.com/t/jenkins-docker-host/14191/2 "2022-11-03T10:36:24Z")

</div>

折腾了好长时间，其实就是一个用户权限的问题。
