4. docker compose up, and Everything That Broke Getting There
What Docker actually replaces
Section titled “What Docker actually replaces”Lessons 1-3 installed everything by hand — Node, Postgres, Redis, Nginx — tightly coupled to one Ubuntu VM’s exact package versions and file paths. A container isn’t a lightweight VM; it’s a process that shares the host’s kernel but gets its own isolated view of the filesystem and network, via Linux namespaces and cgroups. Package it correctly once, and it runs identically anywhere Docker runs.
The backend Dockerfile installs dependencies before copying source, so Docker’s layer cache only reinstalls when package.json actually changes. The frontend is a genuine multi-stage build: one stage runs npm run build, a second clean stage starts from Nginx and copies in only the compiled static output — no Node, no source code, in the final image.
Postgres and Redis connect over Docker’s own internal DNS — the backend connects to the literal hostname postgres, which Compose resolves to whatever container is running that service. The application code never changed; only the value of DB_HOST moved from localhost to postgres.
Bug one: the same dependency conflict, inside Docker this time
Section titled “Bug one: the same dependency conflict, inside Docker this time”The Vite/plugin-react peer-dependency conflict from Lesson 1 resurfaced during the Docker build itself. This time the fix applied was --legacy-peer-deps in the Dockerfile rather than the version bump used earlier — a quicker fix that unblocks the build, though it papers over the mismatch rather than resolving it the way the earlier fix did.
Bug two: products missing, but only from the VM’s IP, not localhost
Section titled “Bug two: products missing, but only from the VM’s IP, not localhost”The app loaded fine from the VM’s own localhost but showed no products from the actual host browser hitting the VM’s IP. Root cause: VITE_API_BASE_URL had been baked into the compiled JS at build time as http://localhost:3001 — and every browser that isn’t the VM itself has no chance, since it’s asking its own localhost for an API that was never there. Fixed by building with a relative value instead of a different hardcoded host, and adding an /api/ proxy block to the frontend’s own Nginx config so requests stay same-origin no matter where the browser actually is.
Bug three: a DNS error that looked real but wasn’t
Section titled “Bug three: a DNS error that looked real but wasn’t”nslookup postgres from inside the backend container returned NXDOMAIN — alarming, but a red herring. The container’s nslookup implementation appends a default search-domain suffix before querying, which Docker’s internal DNS server doesn’t have a record for; the application’s actual Node resolver never does this and connects fine. Verified with getent hosts postgres instead — a cleaner check that confirms real DNS resolution without the false alarm. Added an explicit shared network and a proper healthcheck-gated depends_on anyway, since both were worth having regardless of the DNS diagnosis.
How this actually looks in production
Section titled “How this actually looks in production”Compose isn’t an orchestrator — no multi-host deployment, no rolling updates, no auto-scaling. But plenty of small teams run production on a single server with Compose behind Nginx, and it holds up fine to moderate traffic. The move to Kubernetes later isn’t a rewrite of any of this: the same Dockerfiles, environment variables, and healthchecks translate directly — only the networking model changes.
Next: Lesson 5, Production-ready Containers.