Skip to content

Docker Compose

These examples run the agent as its own container next to an unmodified DNS server container. Before you start, prepare a namespace and register an agent.

Save the agent credential

Both examples read the agent credential from a file named agent-token next to docker-compose.yml. Docker Compose mounts that file into the agent container as it is on the host, with the same owner and permissions. The agent runs as an unprivileged user, so the file must be readable by all users, or the agent stops with read token file: ... permission denied. To keep the credential from other users on the host, make the directory that holds it private instead:

mkdir -p valgrid-dns && cd valgrid-dns
chmod 0700 .
printf '%s' '<credential>' > agent-token
chmod 0644 agent-token

If you already saved the credential, with umask 077 or as a file readable only by you, run chmod 0644 agent-token and chmod 0700 . in its directory.

CoreDNS

Save docker-compose.yml next to agent-token, and set VALGRID_NAMESPACE_ID:

services:
  # Writes the starter Corefile before CoreDNS starts.
  agent-init:
    image: ghcr.io/valgrid-dns/valgrid-agent:<version>
    command: ["-init"]
    environment:
      VALGRID_COREFILE: /var/lib/valgrid/Corefile
    volumes:
      - zones:/var/lib/valgrid
    restart: "no"

  agent:
    image: ghcr.io/valgrid-dns/valgrid-agent:<version>
    environment:
      VALGRID_API_URL: https://api.valgrid.io
      VALGRID_NAMESPACE_ID: <namespace_id>
      VALGRID_AGENT_TOKEN_FILE: /run/secrets/valgrid_agent_token
    secrets:
      - valgrid_agent_token
    volumes:
      - zones:/var/lib/valgrid
    read_only: true
    cap_drop: [ALL]
    security_opt: ["no-new-privileges:true"]
    restart: unless-stopped

  coredns:
    image: coredns/coredns:1.15.0
    command: ["-conf", "/var/lib/valgrid/Corefile"]
    depends_on:
      agent-init:
        condition: service_completed_successfully
    ports:
      - "53:53/udp"
      - "53:53/tcp"
    volumes:
      - zones:/var/lib/valgrid:ro
    read_only: true
    cap_drop: [ALL]
    cap_add: [NET_BIND_SERVICE]
    security_opt: ["no-new-privileges:true"]
    restart: unless-stopped

secrets:
  valgrid_agent_token:
    file: ./agent-token

volumes:
  zones:
docker compose up -d

See CoreDNS for the starter Corefile and how to change it.

BIND

The agent writes a starter named.conf, an rndc key and the zone list into the shared volume, and after each change sends rndc reload to BIND's control channel on the Compose network.

Save docker-compose.yml next to agent-token, and set VALGRID_NAMESPACE_ID:

services:
  # Writes the starter named.conf, rndc key and empty zone list before BIND
  # starts. Existing files are never overwritten, so your edits are kept.
  agent-init:
    image: ghcr.io/valgrid-dns/valgrid-agent:<version>
    command: ["-init"]
    environment:
      VALGRID_SERVER: bind
    volumes:
      - zones:/var/lib/valgrid
    restart: "no"

  agent:
    image: ghcr.io/valgrid-dns/valgrid-agent:<version>
    depends_on:
      agent-init:
        condition: service_completed_successfully
    environment:
      VALGRID_API_URL: https://api.valgrid.io
      VALGRID_NAMESPACE_ID: <namespace_id>
      VALGRID_AGENT_TOKEN_FILE: /run/secrets/valgrid_agent_token
      VALGRID_SERVER: bind
      VALGRID_RNDC_ADDRESS: bind:953
    secrets:
      - valgrid_agent_token
    volumes:
      - zones:/var/lib/valgrid
    read_only: true
    cap_drop: [ALL]
    security_opt: ["no-new-privileges:true"]
    restart: unless-stopped

  # The control channel (953) is reachable only on this Compose network and
  # needs the rndc key. Do not publish it.
  bind:
    image: internetsystemsconsortium/bind9:9.20
    command: ["-g", "-c", "/var/lib/valgrid/named.conf"]
    depends_on:
      agent-init:
        condition: service_completed_successfully
    ports:
      - "53:53/udp"
      - "53:53/tcp"
    volumes:
      - zones:/var/lib/valgrid:ro
      - bind_cache:/var/cache/bind
    restart: unless-stopped

secrets:
  valgrid_agent_token:
    file: ./agent-token

volumes:
  zones:
  bind_cache:
docker compose up -d

See BIND for the starter named.conf and how to change it.

Next steps

Verify the DNS server, then point clients at it.