Use another way to ensure docker socket is accessible

- check if socket group ID is presented in /etc/group
- if presented, just add 'docker' user to this group
- if not, create 'docker' group and add 'docker' user to this group
Fixes issue #20
This commit is contained in:
Sergey Shambir 2019-03-02 13:43:07 +03:00
parent 02a89f6dac
commit 0a4e3f5753

View File

@ -22,16 +22,26 @@ CRONTAB_FILE=/etc/crontabs/docker
# Ensure dir exist - in case of volume mapping # Ensure dir exist - in case of volume mapping
mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects
# Create docker group using correct gid from host, and add docker user to it ensure_docker_socket_accessible() {
if ! grep -q "^docker:" /etc/group; then if ! grep -q "^docker:" /etc/group; then
DOCKER_GID=$(stat -c '%g' ${DOCKER_SOCK}) # Ensure 'docker' user has permissions for docker socket (without changing permissions)
if [ "${DOCKER_GID}" != "0" ]; then DOCKER_GID=$(stat -c '%g' ${DOCKER_SOCK})
addgroup -g ${DOCKER_GID} docker if [ "${DOCKER_GID}" != "0" ]; then
adduser docker docker if ! grep -qE "^[^:]+:[^:]+:${DOCKER_GID}:" /etc/group; then
else # No group with such gid exists - create group docker
adduser docker root addgroup -g ${DOCKER_GID} docker
fi adduser docker docker
fi else
# Group with such gid exists - add user "docker" to this group
DOCKER_GROUP_NAME=`getent group "${DOCKER_GID}" | awk -F':' '{{ print $1 }}'`
adduser docker $DOCKER_GROUP_NAME
fi
else
# Docker socket belongs to "root" group - add user "docker" to this group
adduser docker root
fi
fi
}
slugify() { slugify() {
echo "$@" | iconv -t ascii | sed -r s/[~\^]+//g | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z echo "$@" | iconv -t ascii | sed -r s/[~\^]+//g | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z
@ -219,6 +229,8 @@ EOF
done done
} }
ensure_docker_socket_accessible
if [ "$1" = "crond" ]; then if [ "$1" = "crond" ]; then
if [ -f ${CONFIG} ]; then if [ -f ${CONFIG} ]; then
build_crontab build_crontab