简体   繁体   English

docker中的jenkins-无法通过unix:///var/run/docker.sock连接到Docker守护程序。 泊坞窗守护程序正在运行吗?

[英]jenkins in docker - Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I'm running https://hub.docker.com/r/jenkinsci/blueocean/ in docker. 我在docker中运行https://hub.docker.com/r/jenkinsci/blueocean/ Trying to build a docker image in jenkins. 尝试在jenkins中构建docker映像。

but i get the following error: 但我得到以下错误:

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

clearly the jenkins version in docker does not have access to the docker binary. 显然,docker中的jenkins版本无法访问docker二进制文件。

I confirmed this by, 我证实了这一点,

docker exec -it db4292380977 bash
docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

"db4292380977" is the running container. “ db4292380977”是正在运行的容器。 It shows the same error. 它显示相同的错误。

Question: 题:

  • how do I allow access to docker in the jenkins container? 如何允许在jenkins容器中访问docker?

The docker client is installed on the jenkinsci/blueocean image, but not the daemon. jenkinsci/blueocean客户端安装在jenkinsci/blueocean映像上,但未安装在守护程序上。 Docker client will use the daemon (by default via the socket unix:///var/run/docker.sock ). Docker客户端将使用守护程序(默认情况下通过套接字unix:///var/run/docker.sock )。 Docker client needs a Docker daemon in order to work, you can read Docker Architecture for more info. Docker客户端需要一个Docker守护程序才能工作,您可以阅读Docker Architecture以获得更多信息。

What you can do: 你可以做什么:

Use docker-in-docker (DinD) image 使用docker-in-docker(DinD)映像

Library Docker image provides a way to run a Docker daemon in Docker, you can then use it from another container. 库Docker映像提供了一种在Docker中运行Docker守护程序的方法,然后可以从另一个容器中使用它。 For example, using plain docker CLI: 例如,使用简单的docker CLI:

docker run --name docker-dind --privileged -d docker:stable-dind
docker run --name jenkins --link=docker-dind -d jenkinsci/blueocean
docker exec jenkins docker -H docker-dind images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

Docker daemon runs in docker-dind container and can be reached using the same hostname. Docker守护程序在docker-dind容器中运行,并且可以使用相同的主机名进行访问。 You just need to provide the docker client with the daemon host ( -H docker-dind in the example, you can also use DOCKER_HOST env variable as described in the doc ). 您只需要为-H docker-dind客户端提供守护程序主机(在示例中为-H docker-dind ,您还可以按照doc中所述使用DOCKER_HOST env变量)。

Mount host machine /var/run/docker.sock in your container 在容器中挂载主机/var/run/docker.sock

As described by @Herman Garcia answer: @Herman Garcia所述,答案:

docker run -p 8080:8080 --user root \
     -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

You need to mount your local /var/run/docker.sock and run the container as root user 您需要挂载本地/var/run/docker.sock并以root用户身份运行容器

NOTE: this might be a security flaw so be careful who has access to the jenkins container 注意:这可能是一个安全漏洞,因此请小心谁可以访问jenkins容器

docker run -p 8080:8080 --user root \
     -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

you will be able to execute docker inside the container 您将能够在容器内执行docker

➜  ~  docker exec -it gracious_agnesi bash                                                                                              
bash-4.4# docker ps                                                                                                                     
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                        
       NAMES                                                                                                                            
c4dc85b0d88c        jenkinsci/blueocean   "/sbin/tini -- /usr/…"   18 seconds ago      Up 16 seconds       0.0.0.0:8080->8080/tcp, 50000
/tcp   gracious_agnesi

Just only try to do the same command but with sudo in the beginning 只是尝试尝试执行相同的命令,但在开头使用sudo

For example 例如

sudo docker images
sudo docker exec -it db4292380977 bash

To avoid use sudo in the future you should run this command in Unix OS 为了避免将来使用sudo,您应该在Unix OS中运行此命令

sudo usermod -aG docker <your-user>

Change for the user that you are using at this moment. 更改当前正在使用的用户。 Remember to log out and back in for this to take effect! 请记住注销并重新登录才能生效! More information about Docker installation click here 有关Docker安装的更多信息,请单击此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Jenkins 无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。 docker 守护进程是否正在运行? - Jenkins Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? docker:无法连接到unix:///var/run/docker.sock上的Docker守护程序。 docker守护程序是否正在运行? - docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? docker-compose | 无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。 docker 守护进程是否正在运行? - docker-compose | Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? docker:无法连接到位于 unix:///var/run/docker.sock 的 Docker 守护进程。 docker 守护程序是否正在运行? - docker:Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? docker compose in bitbucket - 无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。 docker 守护进程是否正在运行? - docker compose in bitbucket - Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? macOS - docker:无法连接到 unix:///var/run/docker.sock 的 Docker 守护程序。 docker 守护程序是否正在运行? - macOS - docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 在 docker 容器上运行 Jenkins。无法连接到 unix:///var/run/docker.sock 上的 Docker 守护进程。 docker 守护进程是否正在运行? - Running Jenkins on docker container.Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? "<i>ERROR :Cannot connect to the Docker daemon at unix:\/\/\/var\/run\/docker.sock.<\/i>错误:无法连接到 unix:\/\/\/var\/run\/docker.sock 上的 Docker 守护程序。<\/b> <i>Is the docker daemon running<\/i> docker 守护进程是否正在运行<\/b>" - ERROR :Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running CentOS 7 - 无法连接到 unix:///var/run/docker.sock 处的 Docker 守护程序。 docker 守护程序是否正在运行? - CentOS 7 - Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? 如何修复错误“无法连接到 unix:///var/run/docker.sock 的 Docker 守护程序。 docker 守护程序是否正在运行” - How to fix the error “Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM