Skip to content

Instantly share code, notes, and snippets.

@batandwa
Last active September 11, 2017 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batandwa/b88997390f34dc533d48f6d966ddd6af to your computer and use it in GitHub Desktop.
Save batandwa/b88997390f34dc533d48f6d966ddd6af to your computer and use it in GitHub Desktop.
Docker and GoSu
#!/bin/sh
# Explained at https://stackoverflow.com/questions/36781372/docker-using-gosu-vs-user#37931896
set -x
# get gid of docker socket file
SOCK_DOCKER_GID=`ls -ng /var/run/docker.sock | cut -f3 -d' '`
# get group of docker inside container
CUR_DOCKER_GID=`getent group docker | cut -f3 -d: || true`
# if they don't match, adjust
if [ ! -z "$SOCK_DOCKER_GID" -a "$SOCK_DOCKER_GID" != "$CUR_DOCKER_GID" ]; then
groupmod -g ${SOCK_DOCKER_GID} docker
fi
if ! groups jenkins | grep -q docker; then
usermod -aG docker jenkins
fi
# drop access to jenkins user and run jenkins entrypoint
exec gosu jenkins /bin/tini -- /usr/local/bin/jenkins.sh "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment