Skip to content
Tutorials Center
My learning

Topics

Lesson 109 of 111 ยท Practice

Choosing Your Deployment Path

A practical guide to running Docker in production: one host with Compose, Swarm, managed container services, Kubernetes or serverless containers, and how to decide.

You can build an image and run it on your laptop. The next question every team asks is: where do these containers run when real users depend on them, and what keeps them alive? The answers range from "one small server and a Compose file" to "a managed Kubernetes cluster with a platform team". Picking too little causes outages; picking too much burns months of work on infrastructure instead of the product.

This lesson is a decision guide. It compares the five realistic paths (a single host with Compose, Docker Swarm, managed container services, Kubernetes, and serverless containers), tells you what each one gives you and costs you, and ends with a short list of questions that usually settles the choice. The commands you can verify on a laptop are shown with real output. Everything that needs a cluster or a cloud account is marked as a read-only example.

The machine used to write this track runs one Docker Engine with Swarm mode switched off, and has no Kubernetes or cloud account. Cluster and cloud snippets are written from knowledge of how those systems behave, and they are kept short on purpose. Check the current documentation of your platform before copying them.

What every path has to solve

Whatever you choose, production needs the same handful of capabilities. Compare options by how each one provides them.

Need Question to ask
Keep it running What restarts a crashed container, and a crashed machine?
Updates Can you ship a new version without users noticing?
Scale Can you run several copies and spread requests across them?
Config and secrets Where do passwords and settings live?
State Where does data live, and how is it backed up?
Networking How does traffic from the internet reach a container (TLS, routing)?
Observability Where do logs and metrics go?
Humans Who is on call, and how many people can operate it?

The last row decides more projects than any technical feature. A tool you cannot operate is worse than a simpler tool you can.

Path 1: one host with Docker Compose

The simplest production setup is one virtual machine, Docker Engine and a compose.yaml. It is much more capable than its reputation suggests. A single modern server can handle thousands of requests per second for a typical web application, and many successful products run on exactly this.

Compose gives you restart policies, health checks, networks, volumes, environment files and one-command updates. Here is a small file with two replicas, checked on a real daemon:

YAML
services:
  app:
    image: nginx:alpine
    restart: unless-stopped
    deploy:
      replicas: 2
CONSOLE
$ docker compose up -d
 Container demo-app-1 Started
 Container demo-app-2 Started
$ docker compose ps --format 'table {{.Name}}\t{{.Service}}\t{{.State}}'
NAME         SERVICE   STATE
demo-app-1   app       running
demo-app-2   app       running
$ docker compose up -d --scale app=3
 Container demo-app-3 Creating
 Container demo-app-3 Created
 Container demo-app-3 Started

deploy.replicas is honored by plain docker compose up, and --scale changes the count on the fly. Two things are not provided, and you must add them yourself: a reverse proxy in front (nginx, Caddy or Traefik; see Project: Multiple Apps Behind a Proxy) because several replicas cannot all publish the same host port, and zero-downtime updates, because docker compose up -d after pulling a new image recreates containers and there is a short gap per container. A proxy with health checks and a staggered restart (update one replica, wait for it to be healthy, update the next) gets you close.

Strengths: you can read and fully understand the whole system in an afternoon; the file you use in development is nearly the file you deploy (Compose multiple files covers per-environment overrides); cost is one server. Limits: the host is a single point of failure (if the machine dies, you restore from backup and start again), and capacity is capped by the biggest machine you are willing to rent.

Choose it when: one team, a handful of services, downtime of minutes during a rare failure is acceptable, and you want the lowest operating cost. Back up volumes (Backup and Restore), keep images in a registry (Registries), and script the deploy so it is repeatable. Many projects should stop here and revisit the question only when a real pain appears.

Path 2: Docker Swarm

Swarm mode is built into Docker Engine: it turns several hosts into one cluster, which keeps the number of replicas you ask for, spreads them over machines, and gives you rolling updates, built-in service discovery, an overlay network and secrets. The vocabulary is small (node, service, stack), and a stack file is a Compose file with a deploy: section. The full tour is in Docker Swarm Basics.

You can check whether the machine you are on is part of a swarm:

CONSOLE
$ docker info --format 'swarm={{.Swarm.LocalNodeState}}'
swarm=inactive

inactive means a normal single engine. Enabling Swarm is one command (docker swarm init), and a deployment looks like this (read-only example, it needs a swarm):

YAML
services:
  web:
    image: registry.example.com/shop/web:1.4.2
    ports:
      - "80:80"
    deploy:
      replicas: 3
      update_config:
        parallelism: 1
        order: start-first
      restart_policy:
        condition: on-failure
Terminal
docker stack deploy -c compose.yaml shop

The order: start-first line asks Swarm to start the new container before stopping the old one, one replica at a time, which is a rolling update with no gap.

Strengths: very low learning curve if you know Compose, no extra software to install, real multi-host high availability. Limits: a much smaller ecosystem and community than Kubernetes, fewer managed offerings, and slower development of new features. It is a reasonable choice for a small team that needs more than one host and values simplicity, but it is not where the industry's momentum, tooling and hiring pool are. Treat it as a stable, modest option, and check that its feature set covers your needs before committing.

Path 3: managed container services from a cloud provider

Every large cloud has a service that runs your container image and handles the machines for you: an app service or container platform that you give an image, a port, CPU and memory, a desired count, and a health check URL. The provider replaces failed instances, load-balances, terminates TLS, and plugs in logging and secrets. Examples are Amazon ECS (with Fargate to hide servers), Azure Container Apps, Google Cloud Run in its always-on mode, and the container products of smaller providers.

A typical deployment is a short description plus one CLI call or a pipeline step (read-only example, using made-up names):

TEXT
service:      shop-web
image:        registry.example.com/shop/web:1.4.2
port:         8080
cpu/memory:   0.5 vCPU / 1 GiB
instances:    min 2, max 6   (scale on CPU 60%)
health check: GET /health every 10 s
env:          from the provider's secret store

Strengths: you get high availability, autoscaling and load balancing without learning a cluster, and your Docker skills transfer directly because the unit of deployment is still an image. Limits: each provider has its own concepts and configuration language (so moving later costs effort), you pay for convenience, and local development with Compose mirrors production only approximately. The honest summary: your Dockerfile is portable, your deployment description is not.

Choose it when: you want production-grade reliability without staffing infrastructure, and you accept tying the deployment layer (not your application) to one provider. For many companies this is the best price-to-effort ratio.

Path 4: Kubernetes

Kubernetes is the most widely adopted orchestrator. It runs on every major cloud as a managed service, on your own servers, and on a developer laptop. It describes your application as objects (Deployments, Services, Ingresses, ConfigMaps, Secrets, and more) that controllers continuously reconcile with reality. From Docker to Kubernetes maps each Docker concept to its Kubernetes equivalent.

A tiny Deployment looks like this (read-only example):

YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
        - name: web
          image: registry.example.com/shop/web:1.4.2
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet: { path: /health, port: 8080 }

Strengths: an enormous ecosystem (ingress controllers, certificate automation, service meshes, operators for databases, GitOps tools), fine-grained control over scheduling and security, autoscaling of both pods and machines, and skills that employers recognize. Limits: real complexity. Even on a managed cluster someone must understand networking, storage classes, upgrades, resource requests, RBAC and observability, and the number of moving parts is a source of outages by itself. You need more YAML than with any other path, and tools such as Helm or Kustomize to manage it.

Choose it when: you run many services with several teams, you need advanced scheduling or multi-region setups, you want vendor independence at the cluster level, or your organization already has the skills. Do not choose it just because it is popular or "what big companies use": a three-person team running one application is usually better served by Path 1 or 3.

Path 5: serverless containers

A serverless container platform runs your image only while it handles requests and can scale to zero when idle. You hand over an image and a port; the platform starts instances on demand, scales them with traffic, and bills by usage. Several clouds offer this directly (Google Cloud Run, AWS App Runner, Azure Container Apps), and some can scale to zero.

Strengths: almost no operations, cost near zero for low-traffic apps, instant scaling for spiky traffic. Limits to design around: containers start and stop at any time (cold starts add latency to the first request), instances must be stateless (no local files you need later; use a database or object storage), background work and long-lived connections have restrictions, and per-request pricing can become more expensive than a fixed server at constant high load.

It fits: APIs, webhooks, small websites, scheduled jobs and anything where traffic is irregular. It fits poorly: databases, anything needing local persistent disks, and workloads that must hold state in memory between requests.

Side by side

Compose on one host Swarm Managed containers Kubernetes Serverless containers
Machines you manage 1 several none or few few (managed) or many none
Self-healing across machines no yes yes yes yes
Rolling updates manual or via proxy built in built in built in built in
Learning curve low low medium high low
Portability of the setup high high low high low
Typical monthly cost at small scale lowest low medium medium to high lowest or zero when idle
Best team size 1-5 1-8 any 5 and up (or with a platform team) any

The values are general tendencies, not guarantees: the details depend on the provider and your workload.

How to decide

Walk through these questions in order and stop at the first confident answer.

TEXT
Is the app one container, with spiky or low traffic and no local state?
  -> serverless containers

Does one decent server (plus backups) satisfy your uptime needs?
  -> Compose on one host

Need several machines, but a small team and a simple setup?
  -> managed container service (or Swarm if you own the servers)

Many services, many teams, need for the broad ecosystem or portability?
  -> Kubernetes (preferably managed)

Some rules of thumb from experience:

  • Start small and keep the door open. Everything above runs the same image. If your Dockerfile is clean, your app is configured through environment variables (Configuring Containers), it logs to standard output, and it exposes a health endpoint (HEALTHCHECK), moving between these paths is mostly a matter of rewriting the deployment description.
  • Keep state out of your containers. The easier your containers are to throw away, the more choices you have. Databases are the exception: many teams use a managed database service rather than running one in a container in production.
  • Count people, not features. Ask who will debug it at 3 a.m. and whether the team can learn it in the time available.
  • Automate the path to production first. A repeatable pipeline with tagged images (Image Tagging Strategy) matters more than the orchestrator behind it. See Project: A Build and Release Pipeline.
  • Do not forget security and logs. Whichever path you take, the checklist in Docker Security Checklist and the logging advice in Logging and Monitoring apply.

A pragmatic growth path many teams follow: Compose on one server, then a managed container service as soon as downtime costs more than the service, and Kubernetes only when the number of services and teams makes a shared platform worth its overhead.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A two-person startup runs one web app and a database, and a few minutes of downtime per year is acceptable. What is usually the best starting point?

    One host with Compose is simple, cheap and understandable. The host is a single point of failure, but for this team the trade-off is acceptable.
  2. 2. What does docker info --format 'swarm={{.Swarm.LocalNodeState}}' print on a normal single Docker Engine?

    Swarm mode is off until you run docker swarm init or join a swarm, and the state is then inactive.
  3. 3. Which statement about portability across deployment paths is most accurate?

    All the options run standard images. What differs is how you describe replicas, networking, secrets and updates.
  4. 4. Which workload is a poor fit for serverless containers?

    Serverless instances can start, stop and move at any time, so they must be stateless. Stateful services need persistent storage and a stable identity.
  5. 5. Why does docker compose up -d --scale app=3 alone not give a complete high-availability setup?

    Compose starts the replicas on the same machine. Without a reverse proxy they cannot share one published port, and a host failure takes all of them down.

Summary

  • Production needs restarts, safe updates, scaling, config and secrets, storage, routing and observability. Compare options by how they provide these, and by who has to operate them.
  • Compose on one host is simple, cheap and enough for many projects; add a reverse proxy, backups and a scripted deploy.
  • Swarm adds multi-host clustering and rolling updates with little to learn, but has a much smaller ecosystem.
  • Managed container services remove server management; your image is portable, your deployment settings are not.
  • Kubernetes offers the largest ecosystem and control at the price of real complexity; prefer it when many services and teams justify it.
  • Serverless containers suit stateless, spiky workloads and can scale to zero, but not stateful services.
  • Keep containers disposable, configured by environment variables and logging to standard output, so you can change paths later.

Next: Docker Interview Questions