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.
chmod 777 /var/run/docker.sock
This worked like a charm
Success for me
sudo usermod -a -G docker $USER
reboot
in my case it was just starting docker service :
sudo service docker start
If you want to keep it simple, use fixdockergid on your Dockerfile.
The user jenkins
needs to be added to the group docker
:
sudo usermod -a -G docker jenkins
Then restart Jenkins.
If you arrive to this question of stack overflow because you receive this message from docker, but you don't use jenkins, most probably the error is the same: your unprivileged user does not belong to the docker group.
You can do:
sudo usermod -a -G docker alice
or whatever your username is.
You can check it at the end doing grep docker /etc/group
and see something like this:
docker:x:998:alice
in one of the lines.
Then change your users group ID to docker
:
newgrp docker
2019-02-16
Most of the steps were the same for me as the others has written. However, I was not able to add jenkins to the group docker using usermod with the mentioned solutions.
I tried the following command from the docker host, and from the running docker container:
sudo usermod -a -G docker jenkins
(I entered to the running docker container with the following command from the docker host:
docker exec -t -i my_container_id_or_name /bin/bash
)
Received from docker host:
usermod: user 'jenkins' does not exist
Received from docker container:
We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:
#1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.
[sudo] password for jenkins:
I didnt know the password.
Without the sudo
part of the command, in the docker container I received:
usermod: Permission denied. usermod: cannot lock /etc/passwd; try again later.
Solution: I entered to the running docker container from the docker host with the following command:
docker exec -t -i -u root my_container_id_or_name /bin/bash
Now, I entered as root, and issued the following command:
usermod -a -G docker jenkins
Then, from the docker host, I restarted my running docker container with the following command:
docker restart my_container_id_or_name
After that, I started the jenkins job and it finished with success.
I only used the root user to issue the usermod
command for the user jenkins
.