Skip to content

Add --group-add for Docker socket access when running gateway as non-root #26749

Closed

Description

@lpcox

Context

PR #26658 adds --user $(id -u):$(id -g) to the MCP gateway Docker run command so log files are readable by downstream steps. However, the container process only inherits the primary GID — supplementary groups (like docker) from the host are not carried into the container.

This means the gateway container cannot access the bind-mounted Docker socket (/var/run/docker.sock), which is typically owned by root:docker. Without socket access, the gateway cannot launch backend MCP server containers.

Proposed Fix

Add --group-add to dynamically include the Docker socket's owning GID:

// In mcp_setup_generator.go, after the --user line:
containerCmd.WriteString(" --group-add $(stat -c '%g' /var/run/docker.sock)")

This produces:

docker run -i --rm --network host \
  --user $(id -u):$(id -g) \
  --group-add $(stat -c '%g' /var/run/docker.sock) \
  -v /var/run/docker.sock:/var/run/docker.sock \
  ...

Why this works

  • stat -c '%g' /var/run/docker.sock resolves the socket's owning GID at runtime (e.g., 121 for docker group)
  • --group-add adds it as a supplementary group inside the container
  • Works regardless of what GID the docker group has on any given host

Companion PR

  • gh-aw-mcpg#3985 — makes /etc/hosts write non-fatal for non-root execution

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugmcp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions