Repository navigation
Configuration
A service becomes a Bouncer Service by having an x-bouncer block. Everything else is standard Compose: the replica count is deploy.replicas, the ports are the service's ports: and expose:. Your compose file is never rewritten; the derived project is built in memory on every run.
services:
api:
image: registry/api:2.3
deploy: { replicas: 3 }
restart: unless-stopped
ports:
- "127.0.0.1:8080:8080" # Envoy publishes 127.0.0.1:8080 → replicas :8080
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:8080/health"]
interval: 5s
x-bouncer:
bounce_method: crossover
bounce_margin_factor: 0.95
bounce_overprovision_factor: 1.0
min_task_uptime: 10s
bounce_health_timeout: 300s
healthcheck: { mode: http, uri: /health }
drain_method: envoy
drain_method_params: { delay: 95s }
history_max: 100
upgrade_types: [tailscale-control-protocol]
worker:
image: registry/worker:1.4
expose: ["8001"] # internal Service: Envoy listens on worker:8001
x-bouncer: {} # all defaultsx-bouncer: {} is a complete configuration: every key has a default.
All problems in a service's block are collected and reported together. Any configuration error exits with code 2 before anything is pulled, locked or changed.
| Key | Type | Default | Validation |
|---|---|---|---|
bounce_method |
string | crossover |
one of crossover, upthendown, downthenup, brutal
|
bounce_margin_factor |
number | 0.95 |
0 to 1 inclusive |
bounce_overprovision_factor |
number | 1.0 |
0 to 1 inclusive |
min_task_uptime |
duration | 10s |
Go duration, not negative |
bounce_health_timeout |
duration | 300s |
Go duration, not negative |
healthcheck.mode |
string | http |
only http (or omitted) |
healthcheck.uri |
string | unset: GET /, any status below 500 passes |
any path; set, only 2xx passes; empty keeps the default |
drain_method |
string | envoy |
one of envoy, http, noop
|
drain_method_params.delay |
duration | 60s |
Go duration, not negative |
drain_method_params.drain |
HTTP call | none | required when drain_method: http
|
drain_method_params.is_safe_to_kill |
HTTP call | none | required when drain_method: http
|
drain_method_params.stop_draining |
HTTP call | none | optional |
history_max |
integer | 100 |
0..1000
|
proxy_image |
string | envoyproxy/envoy:v1.39.1 |
not validated; see below |
upgrade_types |
list of strings | none (websocket is always allowed) |
each one Upgrade header token: not empty, no spaces or commas |
Durations use Go syntax: 500ms, 95s, 5m, 1h30m. A bare number such as 60 is rejected.
Unknown keys anywhere in the block are rejected (x-bouncer: json: unknown field "..."), so a typo never silently falls back to a default.
How old replicas are replaced. See Bounce methods for animations and when to pick each:
-
crossover(default): rolling, bounded by the two factors below. -
upthendown: all new replicas healthy before any old one drains. -
downthenup: all old replicas drained before any new one starts (a gap in service). -
brutal: start all new, then stop all old without health gates or drain waits (development only).
Used by crossover only; the other methods fix their own limits. With N = deploy.replicas:
-
maxUnavailable = floor(N × (1 − bounce_margin_factor)): how many of the N may be missing during the bounce. -
maxSurge = ceil(N × bounce_overprovision_factor): how many extra replicas may exist.
If both come out as 0, the surge becomes 1 so the bounce can always progress. The Bounce methods page has the rounding rules and worked examples.
How long a new replica must stay continuously healthy (Envoy, and Docker if it has a healthcheck) before it counts towards replacing an old one. It gates draining only; up finishes once all N new replicas are healthy. See Draining and health.
How long a new replica has to become healthy, counted from when it was created or from the start of the current run, whichever is later. When it expires the bounce fails, unhealthy new replicas are removed, and up exits 1; old replicas keep serving. It also sets how soon an abandoned lock counts as stale. See Draining and health.
Envoy's active health check on every replica:
healthcheck: { mode: http, uri: /ready }Only mode: http exists. Envoy sends GET <uri> to each replica on the Service's first port every second. With no uri, Envoy sends GET / and any status from 200 to 499 passes (the app is up and speaking HTTP; a 404 or 401 on / is fine, a 5xx or no answer fails), so a service with no health endpoint works as is. With a uri set, only a 2xx passes. This is independent of the Compose healthcheck: on the service, which stays on the replicas and is optional.
How an old replica is taken out of service: envoy (wait for its connections to close), http (call your hooks), noop (stop at once). delay is the upper bound on the wait. An HTTP call is:
drain_method: http
drain_method_params:
delay: 120s
drain: { method: POST, path: /admin/drain, success_codes: [200, 202] }
is_safe_to_kill: { path: /admin/idle } # GET, any 2xx
stop_draining: { method: POST, path: /admin/undrain }| Field | Default |
|---|---|
method |
GET |
path |
none (send a path) |
success_codes |
any 2xx
|
Semantics, including when stop_draining is sent, are on Draining and health.
How many previous revisions are kept in the replicas' labels, in addition to the current one. history shows them and undo --to-revision can target them. 0 keeps none, so undo has nothing to go back to.
The history label is also capped at 64 KiB. Typical revisions are tiny (100 that change only the image digest take about 5 KiB), but a service with large inline values (a big environment: value, a long command) can hit the budget first: then the oldest revisions are dropped until it fits, and up/undo warn History trimmed: to N revisions (64 KiB label budget). See How it works.
The Envoy image for this Service's proxy. The default is pinned. A replacement must be based on the official Ubuntu-based envoyproxy/envoy image: the proxy's entrypoint, health check and Bouncer's admin calls run bash (with /dev/tcp), cat, grep, mv, mkdir and printf inside it, so distroless variants do not work. The lock container is created from the proxy image of the first Service in name order.
HTTP upgrades the proxy passes through to the replicas, besides websocket, which always passes. Envoy answers 403 to an Upgrade request of any type not listed. Values are matched without case (they are lowercased) and duplicates are dropped. For example, Tailscale's control protocol needs upgrade_types: [tailscale-control-protocol].
An upgraded connection (a WebSocket) has no idle timeout at the proxy, as plain requests have no route timeout: the app's own timeouts govern. Changing upgrade_types changes the proxy's definition, so the next up recreates the proxy (see Troubleshooting).
A Service needs at least one port, from ports:, expose: or both. The proxy takes them over: it publishes the ports: and exposes the expose: entries, and listens with Envoy on each distinct container (target) port. Replicas get no published ports; they keep expose:.
-
ports:short or long syntax.protocolmust betcp(or omitted). Long syntax may setapp_protocol, but onlyhttpis accepted. -
expose:entries are single ports,"8001"or"8001/tcp". Ranges andudpare rejected. - Two published ports with the same target share one Envoy listener and cluster. Two Services may use the same container port: each has its own proxy.
- The first port (the first
ports:entry, else the firstexpose:entry) is the one Envoy health-checks on and the onedrain_method: httpcalls go to. - Envoy listens dual-stack (
::, IPv4 included), so on a network withenable_ipv6: trueclients reach the proxy over IPv6 too. On an IPv4-only network it listens the same way; only on a host whose kernel has IPv6 off entirely (ipv6.disable=1) does it fall back to IPv4 only. - Envoy's admin interface listens on
127.0.0.1:9901inside the proxy. If a Service uses container port9901, admin moves to19901; if it uses both, that is a configuration error.
ports:
- "8080:8080" # host 8080 → proxy :8080 → replicas :8080
- target: 8081
published: "8081"
host_ip: 127.0.0.1
app_protocol: http # allowed; anything else is rejected
expose: ["9000"] # proxy :9000 on the project network onlydepends_on between Bouncer Services works; stop and down order follows it across proxies and replicas, so a dependent stops before both the proxy and the replicas of the Service it depends on.
A Service runs a proxy plus several replicas, so settings that pin one container's identity are rejected:
| Setting | Why |
|---|---|
container_name |
it runs several replicas |
mac_address (service level) |
the proxy and every replica would share it |
networks.<net>.ipv4_address, ipv6_address, mac_address, link_local_ips
|
same |
any x-bouncer key not listed above |
catches typos |
healthcheck.mode other than http
|
only HTTP health checks exist |
ports with protocol: udp, app_protocol other than http
|
only HTTP over TCP is proxied |
expose ranges or udp
|
one TCP port per entry |
a pre_start hook with per_replica: true
|
Compose does not support it yet and rejects it the same way |
no ports: and no expose:
|
nothing to proxy (a Service whose only port is rejected gets that port's error alone) |
a service named <S>-app next to a Service S
|
that name is reserved for the replicas |
network_mode: host, none, container:<name> or service:<name> on a Service |
the proxy reaches its replicas over a Docker network |
network_mode, ipc or pid set to service:<S>, or volumes_from: [<S>] (or service:<S>), on any service, where S is a Service |
S is the proxy now, not the app: <svc>: network_mode service:web points at web's proxy; bouncer services can't share namespaces or volumes
|
| a project and service name making replica names over 63 characters | see Name length |
a label starting with dev.cuza.bouncer. on any service, Bouncer Service or plain |
Bouncer finds its proxies and replicas by those labels: a plain service carrying them would be taken for a replica, drained and removed |
These are checked across the whole project, inactive profiles included, and exit 2 before anything runs.
Network aliases are allowed: they move to the proxy, so clients resolve them to Envoy, not to an individual replica.
Replicas are named <project>-<service>-app-<n>, and Envoy finds them by that name through Docker's DNS, where a name is at most 63 characters. Bouncer allows four digits for <n> and rejects a project whose names could exceed that:
service "a-long-service-name": replica names like myproject-a-long-service-name-app-1000 are 64 characters, over the 63-character DNS name limit; use a shorter project name (-p) or service name
The proxy (<project>-<service>-1) is always shorter, and the lock container (<project>-bouncer-lock) is never looked up by name.
A Service (or plain service) with build: is built by up through Compose's own build, before the lock and before anything changes; a failed build exits 2. Like docker compose up --build, up builds every time: an unchanged build is a cached no-op, and a changed Dockerfile, build context or build arg produces a new image.
- Without
image:, the image is named<project>-<service>after your service name, as Compose names it, never after the replicas'<service>-app. - Replicas run the image by its name, and the built image ID is part of the spec, in the
dev.cuza.bouncer.imagelabel (see What triggers a bounce). A rebuild that makes a different image is a new revision and bounces; one that makes the same image does not.undoruns the exact image of the old revision, by its ID, as long as it has not been removed (docker image pruneremoves untagged images that no container uses); otherwise it fails naming the missing image and the revision. - With BuildKit (the buildx plugin) and the containerd image store, every build gets a new image ID, because its provenance attestation changes. Bouncer compares the image manifest instead: a rebuild holding the manifest the running replicas run keeps their pin and does not bounce.
- Build services are never pulled.
up --pull alwayspasses--pullto the build, so base images are refreshed. -
up --no-buildskips building: the image must already exist.--buildis accepted fordocker composecompatibility.
Replicas get the service's volumes: as written. A named volume (data:/var/lib/app) is shared by every replica and survives bounces and down. An anonymous volume (- /var/lib/app, or a VOLUME in the image) is created per replica: each new replica starts with an empty one, and it is removed with its replica when that replica is drained. Use a named volume to persist data across bounces (and make sure the app tolerates several replicas sharing it).
A Service may have profiles:. up --profile x starts and bounces it; an up without that profile leaves it alone, neither starting nor bouncing it. ps and stop see its proxy and replicas whether or not the profile is active, and down removes its proxy and replicas even without that profile, so none is left holding a port. Plain services in an inactive profile are left running by down, as docker compose down does; down --profile x (or --profile "*") removes them too.
up pulls every image it needs before taking the lock, so a slow or failing pull never leaves a bounce half done. Compose itself is then told never to pull.
- Services with
build:are built instead, see Building images. - Without
--pull, each service'spull_policydecides:alwayspulls,neverandbuildskip, and anything else (missing, the default, ordaily/weekly/every_<duration>) pulls only when the image is not present locally. -
up --pull always|missing|neveroverrides every service's policy for that run. - The proxy image is pulled when missing (unless
--pull never), because the proxy and the lock container are created from it. -
docker bouncer pull [SERVICE…]pulls every selected image, plus the proxy image, unconditionally, and changes nothing else. - With
platform:a service's image counts as present only when it is held for that platform (OS, architecture and variant when given): a tag held locally for another platform only is pulled. - A pull error exits
2; nothing has changed.
undo also pulls the images of the revisions it restores, before taking the lock, using each service's pull_policy.
A provider: service's variables reach the replicas of a Service that depends on it. Providers run on each bounce step that creates replicas, besides the run of up's plain convergence; see Operations.
N is the service's deploy.replicas (or scale:), default 1. The replica count is not part of a revision's spec, so changing only deploy.replicas scales without a bounce: scaling up adds replicas of the current revision next to the existing ones, and scaling down drains the surplus with the configured drain method. No new revision is created.
deploy.replicas: 0 removes every replica, and with them the Service's revision history, which lives on the replicas' labels: up warns Scaling to 0 replicas: history lives on the replicas and is lost at 0. See Operations.
A Service bounces when the spec hash of its replica config differs from the dev.cuza.bouncer.spec-hash label of the running replicas. The spec is the service minus ports:, network aliases, x-bouncer, the replica count and Bouncer's own labels. So:
- a rebuilt image with a different ID (see Building images);
- an image reference that now names another image, such as a tag moved by a pull: each revision records the exact image its reference named, in the
dev.cuza.bouncer.imagelabel:repo@sha256:…when the local image has a digest for the reference's repository, otherwise the image ID (built or only tagged locally images); a reference that already has@sha256:…is exact as written. The replicas still run the reference as written; - a new image, command, environment variable, volume, label, healthcheck, resource limit and so on triggers a bounce;
- changing
deploy.replicasscales without one; - changing
x-bouncersettings alone does not bounce (they take effect on the next bounce);healthcheck.uriis applied to the running proxy in place on the nextup; changes that alter the proxy's own definition, such asportsorproxy_image, recreate the proxy instead (see Troubleshooting); - keys loaded from an
env_fileare stripped from the spec before hashing, so changing only a value inside an env file does not trigger a bounce. Change something else (for example a label) to roll it out. See How it works.