Container Orchestration for Small Teams
Run multi-service apps without Kubernetes: Docker Compose for local and staging, health checks, resource limits, graceful shutdown, and a path to scale.
On this page
- Introduction
- Why Not Kubernetes (Yet)
- Docker Compose: One File, Many Services
- Health Checks: The Orchestrator’s Eyes
- Resource Limits and Graceful Shutdown
- Dependency Ordering and the Start Problem
- From Compose to Production
- Image Building, Layer Caching, and Secrets in Production
- Health Checks and the Readiness Probe
- Conclusion
Introduction
Container orchestration has a reputation for requiring Kubernetes, and Kubernetes has a reputation for requiring a platform team. Neither is true for a small team running a handful of services. Docker and Docker Compose give you most of the operational value of orchestration — reproducible environments, health checks, resource limits, dependency ordering, graceful shutdown — at a fraction of the complexity, and they scale from a developer laptop to a single production host to a small cluster without a rewrite. This article covers the orchestration a small team actually needs: Compose for local and staging, the production primitives that keep a container alive, and the discipline that makes the jump to a larger orchestrator a choice rather than an emergency.
Why Not Kubernetes (Yet)
Kubernetes solves a real problem: scheduling containers across many hosts, rebalancing on failure, and providing a uniform API for a large organization. It also brings an operators’ worth of complexity — control plane, ingress controllers, storage classes, RBAC, networking overlays — that a team of five does not have the capacity to run. The cost of a misconfigured Kubernetes cluster is higher than the cost of the problem it solves at small scale, and the time spent tending the cluster is time not spent on the product. The pragmatic path is to start with Compose, move to a managed single-host or small-cluster solution when you outgrow a laptop, and adopt Kubernetes only when the scheduling problem it solves is actually your problem. Many successful products never reach that point.
Docker Compose: One File, Many Services
A Compose file describes the whole application: the services, their images, their dependencies, their environment, their ports, and their volumes. It is the single source of truth for the local environment, and with minor variation it is the staging environment too. The value is reproducibility: every developer runs the same database, the same Redis, the same API, with the same configuration, and “works on my machine” becomes “works in Compose.”
# docker-compose.yml
services:
api:
build: ./api
environment:
DATABASE_URL: postgres://app:app@db:5432/app
REDIS_URL: redis://redis:6379
NODE_ENV: production
depends_on:
db:
condition: service_healthy
redis:
condition: service_started
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 3s
retries: 3
start_period: 15s
deploy:
resources:
limits: { cpus: "1.0", memory: 512M }
restart: unless-stopped
stop_grace_period: 30s
db:
image: postgres:16
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: app
POSTGRES_DB: app
volumes: ["db-data:/var/lib/postgresql/data"]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app"]
interval: 5s
retries: 5
restart: unless-stopped
redis:
image: redis:7
restart: unless-stopped
volumes:
db-data:
Read this file as the application’s architecture: the API depends on the database and Redis, the database must be healthy before the API starts, the API exposes a health endpoint, it is limited to one CPU and 512MB of memory, and it restarts if it crashes. Every operational concern is declared in one place, version-controlled, and shared by the whole team.
Health Checks: The Orchestrator’s Eyes
A health check is how the orchestrator knows a container is alive and ready. Without one, the orchestrator restarts on crash only — it cannot detect a container that is running but wedged, and it routes traffic to a container that has started but is not yet ready. Two checks serve different purposes. The liveness check (the healthcheck above) detects a wedged process; if it fails, the container is restarted. The readiness check (often the same endpoint, used by the load balancer) detects a started-but-not-ready process; if it fails, traffic is routed elsewhere until it passes.
// A health endpoint that distinguishes readiness from liveness.
app.get("/health", (req, res) => {
if (shuttingDown) return res.status(503).end(); // draining -> not ready
res.status(200).json({ status: "ok" });
});
app.get("/health/live", (req, res) => res.status(200).json({ status: "alive" }));
The health endpoint should be cheap — no database queries, no external calls — because it runs every few seconds. A health check that queries the database couples the container’s liveness to the database’s availability, so a database blip restarts every container simultaneously. Check the process itself for liveness, and check dependencies in a separate, deeper check that an operator runs on demand.
Resource Limits and Graceful Shutdown
A container without resource limits can consume the whole host, starving its neighbors. Set CPU and memory limits on every service so a misbehaving container is contained — quite literally. The memory limit is the more important one: a container that exceeds its memory limit is killed by the OOM killer, which is a crude but effective backstop against a memory leak taking down the host.
Graceful shutdown is the difference between a deploy that drops in-flight requests and one that does not. When the orchestrator stops a container, it sends SIGTERM and waits stop_grace_period before sending SIGKILL. The application must listen for SIGTERM, stop accepting new requests, let in-flight requests finish, and close database connections — all within the grace period.
let shuttingDown = false;
const server = app.listen(3000);
process.on("SIGTERM", async () => {
shuttingDown = true; // /health starts returning 503; the LB stops sending traffic
server.close(); // stop accepting new connections
await drainInFlight(); // wait for active requests (with a timeout)
await db.close();
process.exit(0);
});
The sequence matters: signal the load balancer to stop routing (via the health check returning 503), then close the listener, then drain, then exit. Skip the first step and the load balancer keeps sending traffic to a container that is closing its listener, producing connection resets for the duration of the drain.
Dependency Ordering and the Start Problem
depends_on with condition: service_healthy makes the API wait for the database to be not just started but healthy — accepting connections. This solves the classic race where the API starts faster than the database, fails to connect, and crashes. For services that do not have a health check, use service_started and add retry logic in the application, because “started” does not mean “ready.” The robust pattern is a health check on every dependency and service_healthy on every depends_on, so the ordering is based on readiness rather than process start.
From Compose to Production
Compose is a local and staging tool; for production on a single host, run the same containers with docker compose up -d behind a reverse proxy (Caddy, Traefik, nginx) that handles TLS and routing. For multiple hosts, the smallest step up is a managed container service (AWS App Runner, Google Cloud Run, Fly.io) that handles scheduling and scaling without exposing the Kubernetes API, or a managed Kubernetes (EKS, GKE) if you need the control. The containers, the health checks, the resource limits, and the graceful shutdown are identical in all of these — that is the value of the container contract. You write the application once, and the orchestrator changes underneath without changing the code.
Keep the production environment as close to Compose as possible: the same images, the same environment variables (injected by the platform, not baked into the image), the same health endpoints. The bug that appears only in production because production runs a different image or a different database is the bug you cannot reproduce locally; parity makes it reproducible in Compose.
Image Building, Layer Caching, and Secrets in Production
The container image is the deployable artifact, and its size and build time are properties worth optimizing because they affect every deploy. A Docker image is a stack of layers, each corresponding to an instruction in the Dockerfile, and each layer is cached: if the instruction and its inputs have not changed, the builder reuses the cached layer rather than rebuilding it. The optimization is to order the instructions so the frequently-changing ones come last, so the cache is invalidated only for the layers that actually changed.
# Install dependencies in a layer that changes only when package.json changes.
COPY package.json package-lock.json ./
RUN npm ci
# Copy the source — this changes on every commit, so it comes after the install.
COPY . .
RUN npm run build
If the COPY . . came before the npm ci, every source change would invalidate the install layer, and the dependencies would reinstall on every build — minutes wasted on every commit. By copying only the lockfile first, the install layer is cached across commits that change source but not dependencies, and the build is fast. This is the single most impactful Dockerfile optimization, and it is purely about instruction order.
Use a multi-stage build to keep the final image small. The build stage compiles the application and produces the artifacts; the runtime stage copies only the artifacts into a minimal base image. The build tools, the source, the node_modules with dev dependencies — none of it is in the final image, which contains only what the application needs to run. A Node image with the build tools is 1 GB; a distroless or alpine image with only the compiled output is 50 MB, and the smaller image pulls faster, starts faster, and has a smaller attack surface.
FROM node:22 AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM gcr.io/distroless/nodejs22 AS runtime
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
CMD ["dist/index.js"]
Secrets in production are the part that is easy to get wrong and consequential when it is. Never bake a secret into the image — a secret in an image layer is in the registry, in every pull, and in anyone who can read the registry. Inject secrets at runtime: as environment variables from the orchestrator’s secret store (Kubernetes Secrets, ECS task secrets), mounted as files, or fetched from a secrets manager at startup. The image is the same in every environment; the secrets are provided by the environment, so a staging image is a production image and the only difference is the configuration it runs with.
# Kubernetes: inject the secret as an environment variable at runtime.
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: api-secrets
key: database-url
For secrets needed only during the build (a private npm token to install from a private registry), use the build-time secret mount (RUN --mount=type=secret) which makes the secret available to the build step without writing it to a layer. The secret exists in the build environment, not in the image, and the image can be pushed to a shared registry without leaking the token. This is the difference between ARG (which is in the image metadata and visible in docker history) and a secret mount (which is not), and it is the reason to never use ARG for a secret.
Health Checks and the Readiness Probe
The orchestrator decides whether to route traffic to a pod based on its health checks, and the distinction between liveness and readiness is the one that matters. A liveness probe asks “is this process alive and not deadlocked” — if it fails, the orchestrator restarts the pod. A readiness probe asks “is this process ready to serve traffic” — if it fails, the orchestrator stops routing to it but does not restart it. The difference is critical: a pod that is starting up and has not yet connected to the database fails its readiness probe (do not send it traffic, it will error) but passes its liveness probe (it is not dead, just not ready). If you conflate the two — using a liveness probe that checks the database — the orchestrator restarts the pod during a database blip, and the restart storm makes the blip worse. Separate them: liveness checks the process, readiness checks the dependencies, and the orchestrator responds to each appropriately.
Conclusion
Container orchestration for a small team is Docker Compose for local and staging, the same containers in production behind a reverse proxy or a managed service, and the operational primitives — health checks, resource limits, graceful shutdown, dependency ordering — that keep containers alive and deploys clean. You get reproducibility, health-aware scheduling, and resource isolation without a platform team, and you preserve the option to adopt Kubernetes later without rewriting the application, because the container contract is the same. Start with Compose, get the primitives right, and let the orchestrator grow with the team rather than ahead of it.
Report a problem with this articleOpens a pre-filled issue on GitHub.