Skip to content
Refringe edited this page Oct 28, 2026 · 15 revisions

Docker

Every release of Anchor LFS publishes a container image, and the repository's Docker Compose file runs it. You can also build the image yourself from the multi-stage Dockerfile.

Published Images

Releases publish an image for linux/amd64 and linux/arm64 to ghcr.io/refringe/anchor-lfs:

Tag Points at
0.2.0 Exactly that release
0.2 The newest 0.2.x release
1 The newest 1.x.y release (from 1.0.0 onwards)
latest The highest version released so far

Git tags have a v prefix (v0.2.0); image tags do not. The Compose file uses latest. In production, pin a minor version such as 0.2 to receive fixes without unexpected changes, and move to the next one deliberately (see Upgrades).

Verifying an Image

Images released after 0.1.4 carry a software bill of materials (SBOM), full build provenance, and a GitHub attestation signed by the release workflow. Check the attestation with the GitHub CLI, and list the SBOM's packages with Docker:

gh attestation verify oci://ghcr.io/refringe/anchor-lfs:latest --repo refringe/anchor-lfs
docker buildx imagetools inspect ghcr.io/refringe/anchor-lfs:latest --format '{{ json .SBOM }}'

Docker Compose (Recommended)

The simplest way to run Anchor LFS in Docker:

# Copy and edit the configuration
cp config.toml.example config.toml
# Edit config.toml with your endpoints...

# Linux hosts only: create the data directory owned by the container user
mkdir -p data && sudo chown 100:101 data

# Start the container
docker compose up -d

Default docker-compose.yml

services:
  anchor-lfs:
    # Pin a release such as 0.1 in production. For a local build, run `make docker-build` and use: image: anchor-lfs
    image: ghcr.io/refringe/anchor-lfs:latest
    ports:
      - "5420:5420"
    volumes:
      # On Linux hosts, create the data directory owned by the image's anchor user first:
      # mkdir -p data && sudo chown 100:101 data
      - ./data:/app/data
      - ./config.toml:/app/config.toml:ro
    environment:
      - ANCHOR_LFS_LISTEN=:5420
    read_only: true
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped
    # Keep above shutdown_timeout (default 30s).
    stop_grace_period: 45s

Key Points

  • Image is the newest published release; curl http://localhost:5420/health reports its version
  • Config file is mounted read-only (:ro) at /app/config.toml. Validate it with docker compose run --rm anchor-lfs check
  • To mount the config file at another path, name it with ANCHOR_LFS_CONFIG, not --config. The HEALTHCHECK runs as a separate process that sees the container's environment but not the server's arguments, so with --config it still reads /app/config.toml and the container turns unhealthy:
        volumes:
          - ./config.toml:/etc/anchor-lfs/config.toml:ro
        environment:
          - ANCHOR_LFS_CONFIG=/etc/anchor-lfs/config.toml
  • Data directory is mounted at /app/data for persistent storage (objects, locks, signing key)
  • The container runs as a non-root anchor user (uid 100, gid 101) on a read-only root filesystem, with every Linux capability dropped and no-new-privileges set. The server writes only to /app/data
  • Port 5420 is published on every host interface. When a reverse proxy on the same host fronts the server, publish it on loopback only ("127.0.0.1:5420:5420"), because Docker's published ports bypass host firewalls such as ufw
  • The container automatically restarts unless explicitly stopped
  • stop_grace_period: 45s gives in-flight transfers time to finish when the container stops. Docker otherwise kills it after 10 seconds; keep the value above shutdown_timeout (default 30s)
  • The image has a HEALTHCHECK that runs anchor-lfs healthcheck every 30 seconds, so docker ps shows healthy once the data directory and storage pass the readiness check, and unhealthy if either stops working

Data Directory Ownership on Linux

If ./data does not exist when the container first starts, Docker creates it owned by root. The anchor user cannot write to it, so the server exits with data directory "./data" is not writable and the container restarts in a loop. Create the directory with the right owner before the first start:

mkdir -p data && sudo chown 100:101 data

Docker Desktop on macOS and Windows maps file ownership on bind mounts, so this step is only needed on Linux hosts.

Resource Limits

The Compose file sets no memory limit. Local storage streams uploads to disk, but each upload proxied to S3 (s3_presigned_urls = false) holds one part in memory: 8 MiB, or max_upload_size / 10,000 if that is larger. Git LFS sends up to 8 objects at once per client, so size the limit for the most uploads you expect at the same time. To set one, add mem_limit to the service and GOMEMLIMIT, about 10% lower, to its environment, so the Go runtime frees memory before the container reaches the limit:

    mem_limit: 1g
    environment:
      - GOMEMLIMIT=900MiB

Metrics

To collect metrics, have the server listen for them on every interface inside the container, and publish the port on loopback only:

    ports:
      - "5420:5420"
      - "127.0.0.1:9420:9420"
    environment:
      - ANCHOR_LFS_LISTEN=:5420
      - ANCHOR_LFS_METRICS_ADDRESS=:9420

A Prometheus container on the same Compose network can scrape anchor-lfs:9420 without the port being published. The metrics have no authentication, so never publish the port on a public interface.

Makefile Shortcuts

Command Description
make docker-build Build a local anchor-lfs image from the checked-out source
make docker-up Start containers in the background
make docker-down Stop and remove containers
make docker-logs Tail container logs

Building Your Own Image

To run unreleased or modified code, build the image from a clone of the repository:

make docker-build

This tags the image anchor-lfs and stamps the binary with the Git version, commit and build date. Without make, run the same build directly:

docker build \
  --build-arg VERSION=$(git describe --tags --always --dirty) \
  --build-arg COMMIT=$(git rev-parse --short HEAD) \
  --build-arg DATE=$(date -u '+%Y-%m-%dT%H:%M:%SZ') \
  -t anchor-lfs .

Then set image: anchor-lfs in docker-compose.yml (or use anchor-lfs in place of the published image in docker run). A build without the VERSION argument reports its version as dev.

Running the Container Manually

mkdir -p data && sudo chown 100:101 data  # Linux hosts only

docker run -d \
  --name anchor-lfs \
  -p 5420:5420 \
  -v $(pwd)/data:/app/data \
  -v $(pwd)/config.toml:/app/config.toml:ro \
  --read-only \
  --cap-drop ALL \
  --security-opt no-new-privileges:true \
  --restart unless-stopped \
  --stop-timeout 45 \
  ghcr.io/refringe/anchor-lfs:latest

Docker Compose with S3 Storage

When using S3 storage, you don't need the data volume for objects (but still need it for locks and the signing key):

services:
  anchor-lfs:
    image: ghcr.io/refringe/anchor-lfs:latest
    ports:
      - "5420:5420"
    volumes:
      # On Linux hosts, create the data directory owned by the image's anchor user first:
      # mkdir -p data && sudo chown 100:101 data
      - ./data:/app/data
      - ./config.toml:/app/config.toml:ro
    environment:
      - ANCHOR_LFS_STORAGE_BACKEND=s3
      - ANCHOR_LFS_S3_BUCKET=my-lfs-bucket
      - ANCHOR_LFS_S3_REGION=us-east-1
      - ANCHOR_LFS_S3_ACCESS_KEY_ID_FILE=/run/secrets/s3_access_key_id
      - ANCHOR_LFS_S3_SECRET_ACCESS_KEY_FILE=/run/secrets/s3_secret_access_key
    secrets:
      - s3_access_key_id
      - s3_secret_access_key
    read_only: true
    cap_drop:
      - ALL
    security_opt:
      - no-new-privileges:true
    restart: unless-stopped
    stop_grace_period: 45s

secrets:
  s3_access_key_id:
    file: ./secrets/s3_access_key_id
  s3_secret_access_key:
    file: ./secrets/s3_secret_access_key

Put each credential alone in its own file under secrets/ (a trailing newline is ignored), then make the files readable only by the container user:

chmod 600 secrets/*
sudo chown 100:101 secrets/*  # Linux hosts only

Compose mounts the files read-only under /run/secrets, so, unlike values in environment or a .env file, the credentials do not appear in docker inspect. ANCHOR_LFS_SIGNING_KEY_FILE works the same way for a configured signing key (see Secrets from Files).

Docker Compose with a Reverse Proxy

See the Reverse Proxy page for examples of running Anchor LFS behind Nginx or Caddy using Docker Compose.

Dockerfile Details

The Dockerfile uses a two-stage build:

  1. Build stage (golang:1.27-alpine): Downloads dependencies, compiles a static binary with CGO_ENABLED=0
  2. Runtime stage (alpine:3.24): Minimal image with just the binary, running as a non-root anchor user, with a HEALTHCHECK of ./anchor-lfs healthcheck (30 s interval, 15 s timeout, 30 s start period, 3 retries)

The final image is small and contains only the compiled binary and the Alpine base.

.dockerignore limits the build context to go.mod, go.sum and the non-test .go files, so a local config.toml, data/ directory or .env never reaches the build or its layer cache.

Persistent Data

The /app/data directory inside the container holds:

Path Description
/app/data/org_repo/ LFS objects for the endpoint /org/repo (local storage backend only). Each endpoint's directory is its path without the leading slash, with / replaced by _
/app/data/locks/org_repo/ File lock state (JSON) for the endpoint /org/repo
/app/data/signing.key Auto-generated HMAC signing key

Always mount this as a volume to persist data across container restarts. The directory must be writable by uid 100, gid 101 (see Data Directory Ownership on Linux). See Operations for backups and for upgrading with the published image.

Next Steps

Clone this wiki locally

⌂ 换网址