Docker from day one

January 2025. Starting a project. Could do it locally - node, mysql, everything on the machine. Containerize later.

Decided to use Docker right away. docker-compose.yml from the first commit.

Why right away

  • "Later" never comes. Project grows, more dependencies, harder to migrate.
  • Production will use Docker anyway. Better to have the same environment from the start.
  • New machine - docker-compose up and you're working. No need to install mysql, configure versions.

Initial compose

services:
  mysql:
    image: mysql:8
  backend:
    build: .
  nginx:
    image: nginx

Three services. Minimum to start.

Principle

Start small. Add services only when actually needed.

Redis? Process memory is enough for now. Separate frontend container? Build is in backend for now. Queues? Handling synchronously for now.

Every new container is complexity. Service connections, startup order, shared volumes, networking.

Payoff

Spent an hour setting up compose on day one. Saved days on "works on my machine, not in production".

Dev and prod - same containers. If it works locally - works everywhere.

Advice

If you're starting a new project - docker-compose.yml in the first commit. But keep it simple. You'll have time to complicate it.

← Back to blog