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
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
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
| Symptom | Possible cause | Investigation | Fix |
|---|---|---|---|
| Container exits immediately | Bad command, missing env, crash | docker ps -a, docker logs, inspect exit code | Correct command/config and restart |
| Port already in use | Host port occupied | docker ps, find process listening on port | Choose another host port or stop owner |
| Cannot reach container | Wrong published port/firewall | docker port, inspect network | Map correct container port |
| Containers cannot communicate | Different networks, wrong DNS name | docker network inspect, inspect config | Join shared network and use service name |
| Image build fails | Syntax, missing file, dependency error | Read build stage and cache output | Fix Dockerfile/context/dependency |
| Permission denied | Wrong file owner or mount mode | Inspect user and mount | Adjust ownership or mount permissions |
| Database connection fails | Wrong host, port or credentials | Read logs and DNS resolve from app container | Fix network and secret configuration |
| Compose fails | YAML syntax, duplicate resources, missing volume | docker compose config, docker compose logs | Fix indentation or service config |
Final beginner project
Containerize a static or simple Node.js application:
- Write a Dockerfile.
- Build
simple-app:1.0. - Run it on port 8080.
- Read logs and stop the container.
- Verify the final image has a specific tag.
Intermediate project
Create a Node.js or Spring Boot API and PostgreSQL service:
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:
- Use multi-stage Dockerfiles.
- Use a custom Compose network.
- Add volumes and health checks.
- Run frontend and API as non-root users.
- Add CPU and memory limits.
- Configure secrets outside source control.
- Tag and push immutable images.
- Add tests, scanning and a GitHub Actions pipeline.
- 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.
Public traffic reaches healthy replicas while data and secrets remain protected.
Common Interview Questions
Chapter quiz
Docker Advanced · 15 questions
1.What is Docker Hub?
2.Which command uploads an image?
3.Which reference is immutable?
4.Which instruction switches to an unprivileged process?
5.What does `--read-only` do?
6.Why scan an image?
7.Which instruction copies an artifact between build stages?
8.What should you inspect first for an immediately exiting container?
9.What does `docker stats` show?
10.What does CI normally run on a source change?
11.Why promote one image digest?
12.What should happen after a pull request?
13.Which deployment reference is most precise?
14.What is a rollback?
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

