Skip to content

Access your docker socket safely as read-only, rootless and distroless

License

Notifications You must be signed in to change notification settings

11notes/docker-socket-proxy

Repository files navigation

banner

SOCKET-PROXY

5pxsize5pxversion5pxpulls5px5pxswiss_made

Access your docker socket safely as read-only, rootless and distroless

MAIN TAGS 🏷️

These are the main tags for the image. There is also a tag for each commit and its shorthand sha256 value.

SYNOPSIS 📖

What can I do with this? This image will run a proxy to access your docker socket as read-only. The exposed proxy socket is run as 1000:1000, not as root, although the image starts the proxy process as root to interact with the actual docker socket. There is also a TCP endpoint started at 2375 that will also proxy to the actual docker socket if needed. It is not exposed by default and must be exposed via using - "2375:2375/tcp" in your compose.

Make sure that the docker socket is accessible by the user: specification in your compose, if the UID/GID are not correct, the image will print out the correct UID/GID for you to set:

socket-proxy-1  | 2025/03/26 10:16:33 can’t access docker socket as GID 0 owned by GID 991
socket-proxy-1  | please change the user setting in your compose to the correct UID/GID pair like this:
socket-proxy-1  | services:
socket-proxy-1  |   socket-proxy:
socket-proxy-1  |     user: "0:991"

UNIQUE VALUE PROPOSITION 💶

Why should I run this image and not the other image(s) that already exist? Good question! All the other images on the market that do exactly the same don’t do or offer these options:

Important

  • This image runs the proxy part as a specific UID/GID (not root), all other images run everything as root
  • This image uses a single binary, all other images use apps like Nginx or HAProxy (bloat)
  • This image has no shell since it is 100% distroless, all other images run on a distro like Debian or Alpine with full shell access (security)
  • This image does not ship with any CVE and is automatically maintained via CI/CD, all other images mostly have no CVE scanning or code quality tools in place
  • This image has no upstream dependencies, all other images have upstream dependencies
  • This image exposes the socket as a UNIX socket and TCP socket, all other images only expose it via a TCP socket

If you value security, simplicity and the ability to interact with the maintainer and developer of an image. Using my images is a great start in that direction.

COMPOSE ✂️

name: "traefik" # this is a compose example for Traefik
services:
  socket-proxy:
    image: "11notes/socket-proxy:2.1.1"
    user: "0:0" # make sure to use the same UID/GID as the owner of your docker socket!
    volumes:
      - "/run/docker.sock:/run/docker.sock:ro" # mount host docker socket, the :ro does not mean read-only for the socket, just for the actual file
      - "socket-proxy:/run/proxy" # this socket is run as 1000:1000, not as root!
    restart: "always"

  traefik:
    image: "11notes/traefik:3.2.0"
    depends_on:
      socket-proxy:
        condition: "service_healthy"
        restart: true
    command:
      - "--global.checkNewVersion=false"
      - "--global.sendAnonymousUsage=false"
      - "--api.dashboard=true"
      - "--api.insecure=true"
      - "--log.level=INFO"
      - "--log.format=json"
      - "--providers.docker.exposedByDefault=false" # use docker provider but do not expose by default
      - "--entrypoints.http.address=:80"
      - "--entrypoints.https.address=:443"
      - "--serversTransport.insecureSkipVerify=true" # do not verify downstream SSL certificates
    ports:
      - "80:80/tcp"
      - "443:443/tcp"
      - "8080:8080/tcp"
    networks:
      frontend:
      backend:
    volumes:
      - "socket-proxy:/var/run"
    sysctls:
      net.ipv4.ip_unprivileged_port_start: 80
    restart: "always"

  nginx: # example container
    image: "11notes/nginx:1.26.2"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.default.priority=1"
      - "traefik.http.routers.default.rule=PathPrefix(`/`)"
      - "traefik.http.routers.default.entrypoints=http"
      - "traefik.http.routers.default.service=default"
      - "traefik.http.services.default.loadbalancer.server.port=8443"
      - "traefik.http.services.default.loadbalancer.server.scheme=https" # proxy from http to https since this image runs by default on https
    networks:
      backend: # allow container only to be accessed via traefik
    restart: "always"

volumes:
  socket-proxy:

networks:
  frontend:
  backend:
    internal: true

ENVIRONMENT 📝

Parameter Value Default
TZ Time Zone
DEBUG Will activate debug option for container image and app (if available)
SOCKET_PROXY_VOLUME path to the docker volume used to expose the prox socket /run/proxy
SOCKET_PROXY_DOCKER_SOCKET path to the actual docker socket /run/docker.sock
SOCKET_PROXY_UID the UID used to run the proxy parts 1000
SOCKET_PROXY_GID the GID used to run the proxy parts 1000

SOURCE 💾

PARENT IMAGE 🏛️

Important

This image is not based on another image but uses scratch as the starting layer.

The image consists of the following distroless layers that were added:

GENERAL TIPS 📌

Tip

  • Use a reverse proxy like Traefik, Nginx, HAproxy to terminate TLS and to protect your endpoints
  • Use Let’s Encrypt DNS-01 challenge to obtain valid SSL certificates for your services

ElevenNotes™️

This image is provided to you at your own risk. Always make backups before updating an image to a different version. Check the releases for breaking changes. If you have any problems with using this image simply raise an issue, thanks. If you have a question or inputs please create a new discussion instead of an issue. You can find all my other repositories on github.

created 28.03.2025, 08:42:11 (CET)