Various groups from jenkins and bash shell on docker container

I have installed jenkins master to docker container and started slave using Swarm plugin in docker container. I created a group in docker slave. As soon as I go into the sub container with help docker exec -it <container> bash

and print groups

, my created group will be listed correctly.

However, when I type groups

job descriptions into the shell and execute a job on this created slave, my group does not appear.

Edit: Slave container: just runs jenkins-slave as user jenkins

. At startup, the following code (script: startup.sh) is executed via CMD [ "/startup.sh" ]

. jenkins-slave.sh

provided at https://gist.github.com/sfrehse/02c7d57fad862c71c20f07c59caba240 .

DOCKER_SOCKET=/var/run/docker.sock
DOCKER_GROUP=dockergrp
JENKINS_USER=jenkins

if [ -S ${DOCKER_SOCKET} ]; then
    DOCKER_GID=$(stat -c '%g' ${DOCKER_SOCKET})
    sudo groupadd -for -g ${DOCKER_GID} ${DOCKER_GROUP}
    sudo usermod -aG ${DOCKER_GROUP} ${JENKINS_USER}
fi

/usr/local/bin/jenkins-slave.sh 

      

After running from bash: docker exec -it 8b85afe2b360 groups

output jenkins dockergrp

.

Running a job containing only the following code:

whoami
groups
docker ps

      

outputs

 jenkins
 jenkins
 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.30/containers/json: dial 
         unix /var/run/docker.sock: connect: permission denied

      

The second line is missing a group dockergrp

.

Overall, I cannot access the docker daemon without sudo

and the problem seems to be a missing group. Executing the command docker exec -it <id> docker ps

successfully displays my running containers.

+3


source to share


1 answer


Known issue adding groups does not reboot for already registered users.

Try changing the last line:

sudo su -l jenkins -c /usr/local/bin/jenkins-slave.sh

      



To run the script under the new new name jenkins.

Note. You can add a command exec

to not have a child process, so just replace the current one:

exec sudo su -l jenkins -c /usr/local/bin/jenkins-slave.sh

      

+1


source







All Articles