Skip to content

Instantly share code, notes, and snippets.

@Molin-L
Created November 25, 2025 07:59
Show Gist options
  • Select an option

  • Save Molin-L/828a8df8c090af8039e8e7195dbdfcb9 to your computer and use it in GitHub Desktop.

Select an option

Save Molin-L/828a8df8c090af8039e8e7195dbdfcb9 to your computer and use it in GitHub Desktop.
Apple Silicon runs docker image everywhere
#!/bin/bash
# ubuntu-here: Docker container launcher with privilege mapping
set -e
IMAGE="ubuntu:22.04"
# Get current user's uid and gid
USER_ID=$(id -u)
GROUP_ID=$(id -g)
CURRENT_DIR=$(pwd)
# Check if docker is available
if ! command -v docker &> /dev/null; then
echo "Error: docker is not installed or not in PATH" >&2
exit 1
fi
docker run -it \
--rm \
--platform linux/amd64 \
-v "$CURRENT_DIR:$CURRENT_DIR" \
--user root \
-w "$CURRENT_DIR" \
"$IMAGE" \
bash -c "groupadd -g $GROUP_ID -o -f nogroup 2>/dev/null || true; useradd -u $USER_ID -g $GROUP_ID -m -s /bin/bash noname 2>/dev/null || true; su noname"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment