Merge pull request #50 from pestotoast/fix-docker-issues

fix docker permissions, check if docker GID already exists
This commit is contained in:
Simon Lindner 2021-12-06 16:41:41 +01:00 committed by GitHub
commit 3a67636092
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

16
Containers/mastercontainer/start.sh Normal file → Executable file
View file

@ -15,9 +15,19 @@ elif ! mountpoint -q "/mnt/docker-aio-config"; then
exit 1
elif ! sudo -u www-data test -r /var/run/docker.sock; then
echo "Trying to fix docker.sock permissions internally..."
GROUP="$(stat -c '%g' /var/run/docker.sock)"
groupadd -g "$GROUP" docker && \
usermod -aG docker www-data
DOCKER_GROUP=$(stat -c '%G' /var/run/docker.sock)
DOCKER_GROUP_ID=$(stat -c '%g' /var/run/docker.sock)
# Check if a group with the same group id of /var/run/docker.socket already exists in the container
if grep -q "^$DOCKER_GROUP:" /etc/group; then
# If yes, add www-data to that group
echo "Adding internal www-data to group $DOCKER_GROUP"
usermod -aG "$DOCKER_GROUP" www-data
else
# If the group doesn't exist, create it
echo "Creating docker group internally with id $DOCKER_GROUP_ID"
groupadd -g "$DOCKER_GROUP_ID" docker
usermod -aG docker www-data
fi
if ! sudo -u www-data test -r /var/run/docker.sock; then
echo "Docker socket is not readable by the www-data user. Cannot continue."
exit 1

View file

@ -5,14 +5,8 @@ if ! [ -a "/var/run/docker.sock" ]; then
echo "Docker socket is not available. Cannot continue."
exit 1
elif ! test -r /var/run/docker.sock; then
echo "Trying to fix docker.sock permissions internally..."
GROUP="$(stat -c '%g' /var/run/docker.sock)"
groupadd -g "$GROUP" docker && \
usermod -aG docker root
if ! test -r /var/run/docker.sock; then
echo "Docker socket is not readable by the root user. Cannot continue."
exit 1
fi
echo "Docker socket is not readable by the root user. Cannot continue."
exit 1
fi
if [ -n "$CONTAINER_TO_UPDATE" ]; then