SkillSprout
Chapter 2 · Lesson 6
Advanced
4 min read

Production Architecture and Final Projects

Overview

Production Docker is more than a small container. A production design defines how images are configured, how traffic enters, how data persists, how failures are observed and how releases are reversed. Container orchestration becomes useful when hundreds or thousands of containers must be placed, healed and replaced.

Detailed Notes

Production architecture

text
Users
  |
  v
Load balancer / reverse proxy
  |
  +--> Frontend containers
  |
  +--> API containers
          |
          +--> PostgreSQL
          +--> Redis

The load balancer receives public traffic and sends requests to healthy replicas. API containers communicate with PostgreSQL and Redis through private networks. Images come from a registry. Logs and metrics go to centralized services. Secrets come from a secret store.

Configuration and rollback

yaml
services:
  api:
    image: registry.example/orders-api@sha256:abc123
    deploy:
      replicas: 3
      resources:
        limits:
          cpus: "1"
          memory: 512M
    healthcheck:
      test: ["CMD-SHELL", "wget -q --spider http://localhost:8080/health || exit 1"]
      interval: 10s
      timeout: 3s
      retries: 3

The digest identifies exact deployed content. Keep the previous digest recorded so rollback is a configuration change rather than rebuilding from source.

Troubleshooting matrix

SymptomPossible causeInvestigationFix
Container exits immediatelyBad command, missing env, crashdocker ps -a, docker logs, inspect exit codeCorrect command/config and restart
Port already in useHost port occupieddocker ps, find process listening on portChoose another host port or stop owner
Cannot reach containerWrong published port/firewalldocker port, inspect networkMap correct container port
Containers cannot communicateDifferent networks, wrong DNS namedocker network inspect, inspect configJoin shared network and use service name
Image build failsSyntax, missing file, dependency errorRead build stage and cache outputFix Dockerfile/context/dependency
Permission deniedWrong file owner or mount modeInspect user and mountAdjust ownership or mount permissions
Database connection failsWrong host, port or credentialsRead logs and DNS resolve from app containerFix network and secret configuration
Compose failsYAML syntax, duplicate resources, missing volumedocker compose config, docker compose logsFix indentation or service config

Final beginner project

Containerize a static or simple Node.js application:

  1. Write a Dockerfile.
  2. Build simple-app:1.0.
  3. Run it on port 8080.
  4. Read logs and stop the container.
  5. Verify the final image has a specific tag.

Intermediate project

Create a Node.js or Spring Boot API and PostgreSQL service:

yaml
services:
  api:
    build: ./api
    ports: ["8080:8080"]
    environment:
      DATABASE_URL: postgres://app:learn@database:5432/app
    depends_on:
      database:
        condition: service_healthy
  database:
    image: postgres:16
    environment:
      POSTGRES_DB: app
      POSTGRES_USER: app
      POSTGRES_PASSWORD: learn
    volumes:
      - database-data:/var/lib/postgresql/data
volumes:
  database-data:

Practice network names, environment variables, health checks and persistent storage.

Production-oriented final project

Build frontend + backend + PostgreSQL + Redis:

  1. Use multi-stage Dockerfiles.
  2. Use a custom Compose network.
  3. Add volumes and health checks.
  4. Run frontend and API as non-root users.
  5. Add CPU and memory limits.
  6. Configure secrets outside source control.
  7. Tag and push immutable images.
  8. Add tests, scanning and a GitHub Actions pipeline.
  9. Deploy and perform a rollback to a prior digest.

Knowledge checkpoints

  • Run Nginx on port 8080.
  • Create a custom network and connect two containers.
  • Mount a PostgreSQL volume.
  • Find and fix why a container exits.
  • Explain image, container, volume and network in one sentence each.
  • Write a Dockerfile that a colleague can understand.
  • Diagnose a Compose service that cannot reach the database.

Why orchestration exists

At a small scale, Docker and Compose are useful. At a large scale, platforms need to place containers on hosts, maintain desired replicas, restart failed containers, roll out updates, route traffic and manage secrets. Kubernetes provides these capabilities. Docker remains useful inside Kubernetes as a packaging format and in local development, while Kubernetes itself is not necessary to learn Docker first.

Production Docker architecture
Architecture
UsersLoad BalancerTLS and routingFrontendreplicasAPI replicasPostgreSQLpersistent volumeRediscache
Key point. Users enter through the load balancer.

Public traffic reaches healthy replicas while data and secrets remain protected.

Common Interview Questions

Chapter quiz

Docker Advanced · 15 questions

  1. 1.What is Docker Hub?

  2. 2.Which command uploads an image?

  3. 3.Which reference is immutable?

  4. 4.Which instruction switches to an unprivileged process?

  5. 5.What does `--read-only` do?

  6. 6.Why scan an image?

  7. 7.Which instruction copies an artifact between build stages?

  8. 8.What should you inspect first for an immediately exiting container?

  9. 9.What does `docker stats` show?

  10. 10.What does CI normally run on a source change?

  11. 11.Why promote one image digest?

  12. 12.What should happen after a pull request?

  13. 13.Which deployment reference is most precise?

  14. 14.What is a rollback?

  15. 15.What does Kubernetes add compared with Docker Compose?

0 of 15 answered

Finished this lesson?

0 of 27 lessons done · 0% of the course