6.3Best practices & pitfalls
The essentials in 30 seconds
- Verify: immutable tags in prod, slim non-root scanned images, zero secrets in the image and in git.
- Make reliable: named volume + proof, one network per app, restart + healthcheck, Compose validated by config.
- Operate: CI as the only factory, replayed backups, single TLS proxy, logs with rotation — eight yeses = prod.
Idir's thread — the rule stuck on the wall
After one quarter, Idir stuck his rule on the wall in Algiers: healthy and proven first, fast second. What counted most was not a tool but three habits — immutable tags, proven volumes, validated Compose — and his biggest pitfall narrowly avoided: a latest deployed on a Friday evening, blocked before prod.
Pick a single habit to anchor in your routine, then move to the next one.
The contract of trust
A healthy Docker stack rests on few rules, always applied. Here they are, with their opposites to ban.
✓ To do
- Immutable tags in prod, latest only in dev.
- Systematic non-root USER, official slim bases.
- Zero secrets in the image and in git (run -e, secrets, .env not committed).
- Named volume for data, rm + restart test.
- One network per app, internal database, only the front end published.
- restart + healthcheck on every long-lived service.
- Versioned Compose, validated by config, base + profiles.
- CI as the only factory (SHA+version), cache enabled.
- Automatic backups + tested restore.
- Single reverse proxy, TLS in prod, logs with rotation.
✗ To avoid
- Deploying latest to production.
- Running as root "to simplify".
- Committing .env and secrets, COPYing them into the image.
- Storing the database in the ephemeral layer.
- Publishing every service and the database.
- depends_on with no condition or retry.
- docker run lines copied from memory.
- Building/pushing by hand from the laptop.
- Never replaying a backup.
- One port per app, with no proxy or monitoring.
Ready-to-say script — checking your stack before prod (30 s)
"Immutable tags? Non-root + scan? Zero secrets in git? Volume proven by rm + restart? Restart + healthcheck? Compose config OK? CI as the only factory? Backup replayed? If any no, I fix before prod."
Copy-paste template — pre-deployment prod checklist
docker compose config
docker scout quickview mon-app:1.0
docker compose up -d --build
docker compose ps
docker compose logs -f api
Small business / tight budget
One habit per quarter is enough: tags + proven volumes first, the rest after.
SME in Algiers
Adapt routines to release days: a replayed-backup slot and a down/up proof kept every month.
Remote / hybrid
The #1 discipline remotely: tag, validated config and written proof, even for small stacks.
Intercultural
Check local usages instead of assuming: an unusual port or path must raise an alert everywhere.
48h challenge — apply tomorrow
Screen your stack: zero latest in prod, zero secrets in git, zero unproven volumes. Fix the first gap found.
- I know the 10 reflexes to adopt and the 10 pitfalls to avoid.
- I checked my 3 critical points (tags, secrets, proven volumes).
- I did the 48h challenge or scheduled its date.
Before going live, which reflex protects Idir best?
A good Docker operator is not the one who deploys fastest, but the one whose stacks are versioned and proven.