[英]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: 题:
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: 你可以做什么:
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变量)。
/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.