โ† Back to Projects
๐Ÿณ

From Zero to Production: Full-Stack Bookstore App on AWS Using Docker

Three assignments. Seven breaking problems. One live production deployment.

PlatformAWS EC2 + Docker
StackNode.js ยท MySQL ยท Nginx ยท Docker Compose
TypeContainer Orchestration
Read on MediumView Article โ†’

Overview

What I Built

A production-grade Docker Compose stack running The EpicBook โ€” a Node.js bookstore application โ€” on AWS EC2, with a proper reverse proxy, healthchecks, named volumes, split networks, structured logging, and environment variable management.

Internet โ†“ [Nginx Reverse Proxy] โ€” Port 80 (PUBLIC) โ†“ [Node.js Express Backend] โ€” Port 3000 (INTERNAL ONLY) โ†“ [MySQL 8 Database] โ€” Port 3306 (ISOLATED NETWORK) Networks: frontend-network: Nginx โ†” Backend backend-network: Backend โ†” Database (Nginx CANNOT reach DB) Volumes: mysql-data (named) โ€” data survives restarts nginx-logs (bind mount) โ€” tail logs without entering container
3
Containers Running
89%
Image Size Reduction
7
Problems Debugged
โœ…
All Containers Healthy

7 Problems I Debugged

PROBLEM 1

App built for Heroku โ€” JAWSDB_URL meant nothing inside Docker

The original config used Heroku's database addon string. Fix: rewrote config.json production section to use individual host, username, password fields pointing to the database container by its Docker service name.

PROBLEM 2

Localhost means something different inside Docker

Development config had database host set to 127.0.0.1. Inside Docker each container is its own machine. Fix: changed host to "database" โ€” the service name Docker uses for internal DNS resolution.

PROBLEM 3

Models folder was missing โ€” MODULE_NOT_FOUND on every request

Sequelize needed a models folder to define database tables. The folder was not present after cloning. Fix: cloned the original repository into a temp folder and copied the models directory into the project.

PROBLEM 4

Routes had wrong import paths โ€” ../backend/models vs ../models

Both routes files imported from the wrong path. Fix: used sed to replace the incorrect paths in both files to point to the correct location.

PROBLEM 5

Nginx loading two conflicting config files โ€” 502 Bad Gateway

Nginx was loading both a custom nginx.conf and default.conf simultaneously, creating two server blocks on port 80. Fix: updated the Dockerfile to delete default.conf before copying in the custom config.

PROBLEM 6

Database volume had wrong password baked in from earlier failed runs

MySQL remembered the wrong root password from an earlier broken run regardless of environment variables. Fix: ran docker compose down -v to wipe the volume and start completely fresh.

PROBLEM 7

Database was empty โ€” schema expected "bookstore" but we created "epicbook"

The original schema SQL assumed a database called bookstore. Fix: created the bookstore database manually, granted permissions to the app user, and imported the schema and seed files.

Key Skills

What I Learned

Multi-Stage Docker Builds

Reduced backend image from ~1.3GB to ~145MB (89% reduction) using a build stage and a lean production stage โ€” same technique, applied to Node.js instead of React.

Docker Network Segmentation

Split frontend-network and backend-network so Nginx can reach the backend but cannot reach the database. Defense in depth at the container level.

Healthcheck Startup Chains

Made the backend wait for the database to be healthy, and Nginx wait for the backend. Eliminated the race condition that caused random startup failures.

Named Volumes vs Bind Mounts

Named volumes for persistent data (MySQL), bind mounts for observability (Nginx logs tailable directly on host without entering any container).

Production Debugging Mindset

Every error message tells you exactly what is wrong if you read it carefully. 502 Bad Gateway = Nginx cannot reach backend. MODULE_NOT_FOUND = wrong file path. Debugging is not guessing โ€” it is reading.

DockerDocker ComposeNginxNode.jsMySQLAWS EC2Multi-Stage BuildsHealthchecksNamed Volumes
Read Full Article on Medium โ†’