Introducing a new way to review your PRs.

Read the announcement

basecamp / kamal-proxy

Lightweight proxy server for Kamal

View on GitHub

15 documents · Updated Nov 18, 2026

docs / local-development-environment

Local proxy environment

The local proxy environment is a Docker Compose setup that runs Kamal Proxy beside four copies of a small upstream web application. It gives engineers a runnable integration setup for deploying a target, sending requests through the proxy, inspecting deployment state, and viewing proxy metrics without needing a separate application or host setup.

Compose environment

The Compose environment joins the proxy, upstream application, and metrics collector in one local network. The proxy is built from the repository, while the upstream service is built from the example application and scaled to four replicas. The setup exposes the proxy on local HTTP and HTTPS ports and exposes Prometheus on its local web port. (example/docker-compose.yml• L1-21)

The main services have these roles:

ServiceRoleLocal access
proxyRuns Kamal Proxy with debug logs and a metrics endpoint.http://localhost/, https://localhost/
webSupplies four reachable upstream containers for deployment tests.Reached by the proxy on the Compose network
prometheusScrapes the proxy metrics endpoint at a short interval.http://localhost:9090/

The proxy publishes only loopback-bound ports, so this environment is intended for local use. Prometheus reads its scrape target from example/prometheus.yml, which names the proxy by its Compose service name and metrics port. (example/docker-compose.yml• L16-21, example/prometheus.yml• L1-7)

References: example/docker-compose.yml• L1-21 example/prometheus.yml• L1-7

Upstream sample application

The upstream sample application is a small HTTP server that models a deployable web service. It listens on port 80, returns success from /up for proxy health checks, and returns a time-stamped greeting for other paths. (example/…/main.go• L12-15, example/…/main.go• L17-28, example/…/main.go• L31-40)

Each replica identifies itself with its container hostname. The response also honors the proxy target header when present, so a request can show which deployed target handled it. This makes traffic changes between replicas visible during local experiments. (example/…/main.go• L17-27)

References: example/…/main.go• L12-15 example/…/main.go• L17-28 example/…/main.go• L31-40

Local deployment flow

The local workflow starts the complete environment, registers one upstream replica with the proxy, and then sends browser traffic to the proxy. The deployment command uses the Compose-generated container name as the target, while the proxy service name becomes the logical name used by later commands. (example/README.md• L3-15)

The flow is:

flowchart LR
    A[Start Compose environment] --> B[Build proxy and web images]
    B --> C[Run proxy and four web replicas]
    C --> D[Deploy one web target through proxy CLI]
    D --> E[Proxy checks /up]
    E --> F[Browser request to localhost]
    F --> G[Healthy web replica response]

To start the environment, run docker compose up --build from example/. Use docker compose exec proxy ... for proxy CLI commands. For example, kamal-proxy deploy service1 --target example-web-1 registers the first web replica, and kamal-proxy ls lists the services known to the proxy. (example/README.md• L3-19)

References: example/README.md• L3-19 example/docker-compose.yml• L1-14

Request and observability path

After deployment, client requests enter through the proxy's local HTTP endpoint and are sent to the healthy upstream target. The sample application logs health checks and normal requests, while Prometheus collects the proxy's metrics from its internal metrics port. (example/…/main.go• L12-15, example/…/main.go• L27-28, example/prometheus.yml• L4-7)

This relationship shows how traffic and metrics move through the setup:

sequenceDiagram
    participant User as Browser or client
    participant Proxy as Kamal Proxy
    participant Web as Deployed web replica
    participant Prom as Prometheus

    Proxy->>Web: Health check /up
    Web-->>Proxy: HTTP 200
    User->>Proxy: Request to localhost
    Proxy->>Web: Forward request
    Web-->>Proxy: Greeting response
    Proxy-->>User: Upstream response
    Prom->>Proxy: Scrape metrics on port 9000
    Proxy-->>Prom: Prometheus metrics

References: example/…/main.go• L12-15 example/…/main.go• L27-28 example/prometheus.yml• L4-7 example/docker-compose.yml• L2-8

The environment is a practical entry point for the proxy command interface. Use the proxy server page for the proxy's traffic and deployment model, and the operator CLI page for the commands that manage deployed services.

References: example/README.md• L9-19

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the Compose service names and target names aligned with the deployment examples. A name change can make the documented target unreachable.
  • Keep the proxy metrics port aligned across the proxy command, Prometheus scrape target, and local access instructions.
  • Keep the upstream health path aligned with the proxy's health-check behavior. A change can prevent deployment even when the application is running.
  • Keep local port bindings and request examples aligned so they do not imply external exposure.

Important failure modes

TriggerConsequenceGuard
The upstream does not return HTTP 200 from /up.The proxy does not mark the target healthy, so deployment does not complete.Preserve the sample health endpoint or change the deployment health-check path with the proxy CLI.
The deployment target does not match a Compose web replica name.The proxy cannot reach the requested upstream.Use the current Compose-generated target name shown by the running services.
The proxy metrics port and Prometheus target differ.Prometheus cannot scrape proxy metrics.Keep the proxy command, scrape configuration, and service network port consistent.
The proxy has no deployed service.Requests to the local proxy have no upstream application to serve.Deploy a web target before browsing to http://localhost/.

Key files

FileWhy to read it
example/docker-compose.ymlDefines the runnable proxy, upstream replicas, and Prometheus services.
example/README.mdGives the shortest start, deploy, request, and service-list workflow.
example/…/main.goShows the sample application's health contract and visible request response.
example/prometheus.ymlShows how local Prometheus discovers the proxy metrics endpoint.
example/upstream/DockerfileShows how the upstream sample becomes a small container listening on port 80.