I have a self hosted linux agent, where I can docker, npm, nodeJs installed.
I want to execute a simple container job, where I fetch the publicly available image 'ubuntu:18.04' and just echo a line on to the terminal.
But I end up facing this issue:
Starting: Initialize containers
/usr/bin/docker version --format '{{.Server.APIVersion}}'
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied
'
##[error]Exit code 1 returned from process: file name '/usr/bin/docker', arguments 'version --format '{{.Server.APIVersion}}''.
Finishing: Initialize containers
I researched a bit on to this issue, and added my user to the docker group, restarted the daemon, but still no success.
Any suggestions?
Related
introduction: I'm trying to build an Angular app on the slave, In order not to install nodejs on the slave I use docker on the slave to build and cleanup.
The problem
run docker commands directly on the slave with the Jenkins user works well
jenkins#ubuntu_server:~$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
...
When the jenkinsfile try to run docker commands on the slave it fails with permission denied error.
+ docker inspect -f . node:current-alpine3.10
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/node:current-alpine3.10/json: dial unix /var/run/docker.sock: connect: permission denied
here relevant jenkinsfile part
"ubuntu_server" is a label of the slave
pipeline {
agent {
docker {
image 'node:current-alpine3.10'
label 'ubuntu_server'
args '-v /tmp:/tmp'
}
}
I had the problem as well after adding a new slave node on a remote server.I did what most others suggested, adding to the docker group. I was able to execute docker commands with the user no problem when I SSHed in but I was still getting the error when building with Jenkins.
Turns out Jenkins never closed its connection to the server for the node which I had configured before adding that user to the docker group.
In the end the resolution for me was to go into Jenkins > Manage Jenkins > Manage Nodes and Clouds > {My Node} and disconnect the node. Upon reconnecting it worked fine.
I installed the Docker installation to my UNIX (macOS), once I execute simple commands like,
$ docker run ubuntu
it shows following error prompted in terminal:
docker: Error response from daemon: dial unix docker.raw.sock: connect: no such file or directory.
I tried in several docker commands, but docker daemon throws the mentioned error message.
This is issue of Docker Engine startup not linked with docker demons, I resolved this problem by Reset to Factory Settings option in Docker Troubleshooting pane
Any idea why I can't run docker using Airflow?
The same docker command runs fine from terminal using the user that runs airflow. So there is no permission issue on the Linux side.
But when put it into Airflow dag, it complains
docker: Got permission denied while trying to connect to the Docker
daemon socket at unix:///var/run/docker.sock: Post
http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/create: dial unix
/var/run/docker.sock: connect: permission denied.
The command is simply docker run --rm -v /data:/data:ro docker_image mycommand. It is wrapped inside a python subprocess, so I can't use docker operator.
Note this is not the same issue with the question: How to fix "dial unix /var/run/docker.sock: connect: permission denied" when group permissions seem correct?
There it is a linux permission issue as it cannot run the docker run command. Here the problem is more with Airflow, I think.
Faced a similar issue .
Got it fixed by changing the default_owner(default=airflow) in airflow.cfg to the user having permission to access docker(i.e username belonging to docker group).
Interestingly passing owner in 'default_args' in the DAG definition didn't seem to work
Looks like the reason is in access rights to /var/run/docker.sock.
For dev environment, you can do:
docker exec -ti -u root <container> bash
sudo chmod 777 /var/run/docker.sock
I have Jenkins on Docker, both Jenkins master and slave are Docker containers, with mounted var/run/docker.sock. There is proper connection between them, but when I try to run simple docker "hello-world" as a test (using a Pipeline script), I got famous:
Got permission denied while trying to connect to the Docker daemon
socket at unix:///var/run/docker.sock: Get
http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json?all=1: dial
unix /var/run/docker.sock: connect: permission denied
I've read many times, that my Jenkins user should belong to docker group, then everything shoud work just fine. But apparently, this happens:
jenkins#7401675c7c9e:~$ groups
jenkins docker
jenkins#7401675c7c9e:~$ docker ps -a
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.39/containers/json?all=1: dial unix /var/run/docker.sock: connect: permission denied
Now I completely don't know what am I doing wrong, I've tried everything:
adding RUN usermod -a -G docker jenkins to both Dockerfiles (for
master and slave images)
adding DOCKER_OPTS=' -G jenkins' to /etc/default/docker
adding privileged: true to docker-compose
manually entering containers and using usermod -aG docker jenkins, and relogging later.
No matter what I do, pipeline can't just access docker socket. I am jenkins user, I am in docker group and I still can't do anything with docker daemon. Jenkinsfile is really simple:
pipeline{
agent{
node{
label 'swarm'
}
}
stages {
stage("Just checking"){
steps{
sh 'whoami'
sh 'groups jenkins'
}
}
stage("Hello world!"){
steps{
sh 'docker run hello-world'
}
} ...
And results are:
+ whoami
jenkins
+ groups jenkins
jenkins : jenkins docker
+ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.35/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
script returned exit code 126
I'm just starting to use docker and jenkins and I have no idea what I am doing wrong, does anybody see any obvious mistake?
Following a Docker guides, I try to build a Docker with a command
sudo gradle build buildDocker
and I get an error:
What went wrong:
Execution failed for task ':buildDocker'.
Docker execution failed
Command line [docker push vw98075/demo-docker-postgresql:0.0.1-SNAPSHOT] returned:
denied: requested access to the resource is denied
Based on an information on this site, I try to log into docker first and run the command. After running "docker login", I get another error:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.27/auth: dial unix /var/run/docker.sock: connect: permission denied
And I run
$ ls -l /var/run/docker.sock
whick yields
srw-rw---- 1 root docker 0 Jun 17 21:47 /var/run/docker.sock
How to resolve this problem?
Your user is obviously not in the docker group. So any docker command will need to be run with sudo.