Dependency Mirrors Quickstart (Go & npm)

Why mirrors

  • Faster, more reliable builds; fewer external calls.
  • Helpful for restricted or flaky egress.

Go proxy (GOPROXY)

  • Start a local Go proxy (example container image) and point builds to it.
  • docker-compose.yml (snippet):
version: "3.9"
services:
  goproxy:
    image: goproxy/goproxy:latest
    container_name: goproxy
    ports: ["8081:8081"]
    environment:
      - GONOSUMDB=*
    restart: unless-stopped
  • Use it in builds:
export GOPROXY=http://localhost:8081,direct
go env GOPROXY

npm (optional, Verdaccio)

  • docker-compose.yml (snippet):
services:
  verdaccio:
    image: verdaccio/verdaccio:5
    container_name: verdaccio
    ports: ["4873:4873"]
    volumes:
      - ./verdaccio/storage:/verdaccio/storage
      - ./verdaccio/conf:/verdaccio/conf
    restart: unless-stopped
  • npm/yarn config:
npm config set registry http://localhost:4873
# or per-project .npmrc

Tips

  • Start with Go only if you’re a Go shop.
  • Monitor disk usage and cache hit rate.
  • Document how to disable mirrors (e.g., unset env) for emergency fetches.