Skip to content

Instantly share code, notes, and snippets.

@jt-nti
Created November 13, 2017 17:56
Show Gist options
  • Save jt-nti/92af70cafe4ae9dfe74511d32175f955 to your computer and use it in GitHub Desktop.
Save jt-nti/92af70cafe4ae9dfe74511d32175f955 to your computer and use it in GitHub Desktop.
Ensure jenkins user has permission to access docker daemon socket
#!/bin/bash
if [ -e /var/run/docker.sock ]; then
DOCKER_GID=$(stat -c '%g' /var/run/docker.sock)
else
exit 0
fi
if [ ${DOCKER_GID} ]; then
DOCKER_GROUP=$(getent group ${DOCKER_GID} | cut -d: -f1)
fi
if [ ! ${DOCKER_GROUP} ]; then
DOCKER_GROUP=hdocker
sudo groupadd -for -g ${DOCKER_GID} ${DOCKER_GROUP}
fi
sudo usermod -aG ${DOCKER_GROUP} jenkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment