I am new to docker. I just tried to use docker in my local machine(Ubuntu 16.04) with Jenkins.
I configured a new job with below pipeline script.
node {
stage('Build') {
docker.image('maven:3.3.3').inside {
sh 'mvn --version'
}
}
}
But it fails with below error.
Maybe you should run the docker with option "-u root" from the very beginning
At least that solved my problem
2019-05-26
This worked for me !
Example docker-compose:
use below dockerfile
I faced a similar issue, which is a permission issue and the cause of this issue is because the Docker daemon/server always runs as the
root
user, and wants you to always preface the docker command withsudo
.Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user
root
and other users can only access it usingsudo
.To fix this, here's what worked for me:
Firstly, check if you have a docker group already created:
If you don't find
docker
in the list that is displayed, then you will need to create one:Next, confirm your
user
and yourgroup
using the command below:Scroll through to see the group for docker. It should be of this format
where
docker
is mygroup
andpromisepreston
is myuser
Now we can add your user to the docker group
For Docker Container Files only:
Copy and run the command below in your terminal exactly how it is stated without modifying it in anyway, regardless of the docker image/container/command that you want to run or are trying to run or is casuing the permission issue:
After running the command above, you will need to Log out and log back in so that your group membership is re-evaluated. However, on Linux, you can also run the following command below to activate the changes to groups (Copy and run the command below in your terminal exactly how it is stated without modifying it in anyway, regardless of the docker image/container/command that you want to run or are trying to run or is casuing the permission issue):
You can now verify that you can run docker commands without sudo permissions, by running the command that is causing the permissions issue again, say (Replace
my-command
with the name of your image/container/command):For Docker and Local filesystem files:
If you have a copy of the files on your local filesystem, then you can change the ownership of the application directory where the application files are stored, using this format:
So in my case it will be:
Note: Please run this command inside the parent directory housing the application directory.
That's all.
I hope this helps
While doing production config i got the permission issue.I tried below solution to resolve the issue.
Error Message
Solution: permissions of the socket indicated in the error message, /var/run/docker.sock:
After changes permission for docket.sock then execute below command to check permissions.
In my case, it was not only necessary add
jenkins
user todocker
group, but make that group the primary group of thejenkins
user.Don't forget to reconnect the jenkins slave node or restart the jenkins server, depend on your case.