Last active
November 27, 2025 08:01
-
-
Save stepahn/6ded43e609114c4c93b64429c8bc637d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| HOST_DOCKER_SOCKET=/var/run/docker-host.sock | |
| # Get the GID of the socket | |
| SOCKET_GID=$(stat -c '%g' "$HOST_DOCKER_SOCKET") | |
| # Get the group name from the GID | |
| GROUP_NAME=$(getent group "$SOCKET_GID" | cut -d: -f1) | |
| # If group doesn't exist, create it with the appropriate GID | |
| if [ -z "$GROUP_NAME" ]; then | |
| GROUP_NAME="docker-host-gid-$SOCKET_GID" | |
| sudo groupadd -g "$SOCKET_GID" "$GROUP_NAME" | |
| fi | |
| # Add the current user to the group if not already a member | |
| CURRENT_USER=$(id -un) | |
| if ! id -nG "$CURRENT_USER" | grep -qw "$GROUP_NAME"; then | |
| sudo usermod -aG "$GROUP_NAME" "$CURRENT_USER" | |
| fi | |
| echo "Adding current user $CURRENT_USER to group $GROUP_NAME" | |
| docker context create host --docker "host=unix://$HOST_DOCKER_SOCKET" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| newgrp $(getent group $(stat -c '%g' /var/run/docker-host.sock) | cut -d: -f1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment