Five containers behind one Nginx proxy, tested on every push

A React frontend, an Express API, MongoDB, Redis and an Nginx reverse proxy, orchestrated with Docker Compose. Only the proxy is reachable from outside, and GitHub Actions builds the whole stack and tests it from the outside before any image is published.

Source on GitHub (opens in a new tab)

Stack
Nginx, React, Express, MongoDB, Redis
Orchestration
Docker Compose, health-gated startup
CI/CD
GitHub Actions, images published to GHCR
Checks
13 black-box checks on every push
Logs
Capped at 370 MB for the whole stack

How it fits together

    • BrowserThe only thing outside the stack
    • proxyNginx. Sends / to web and /api/ to api
    • webNginx serving the compiled React files
    • apiExpress, running as a non-root user
    • mongoApp user limited to readWrite on one database
    • redisPassword-protected cache, cache-aside reads
A request enters through the proxy, the only published port. The API, the database and the cache are reachable only on the project's internal network.

The pipeline: ship only what was tested

Every push and every pull request runs on a fresh GitHub-hosted machine. The images that are published are the same ones that were just tested, not a second build.

  1. Create .env. The same script a new clone uses generates fresh passwords. No secrets are stored in GitHub.

  2. Build and start. docker compose up --build --wait returns only when all five healthchecks pass.

  3. Verify. 13 black-box checks: routing, health and readiness, full CRUD, cache hit and miss, data surviving a database restart, and that only the proxy publishes a port.

  4. Publish. On a push to master only, after the checks pass: the api, web and proxy images go to GHCR, tagged with the commit SHA.

  5. Tear down. Always runs, even after a failure, and dumps every container's logs first if something broke.

Decisions, and why

  1. One exposed port. Only the proxy publishes a port. Connections from the host to the API, MongoDB and Redis ports are refused, and the verify script checks that on every run.

  2. The API gets the least access that works. It connects as a MongoDB user with readWrite on its own database only, never the root account, and each container is handed only the variables it uses. Redis never sees the Mongo password.

  3. Healthchecks that prove authentication works. An unauthenticated ping succeeds against a locked MongoDB, and redis-cli exits 0 even on an auth failure. A plain ping would report healthy while every real query fails, so both checks log in.

  4. Startup is gated on health, not on existence. The API does not start until both data stores answer, and the proxy does not start until there is something behind it to route to.

  5. Logs are capped, with one measured exception. Compose's default is no limit, so one chatty service can fill the disk and take the others down. MongoDB gets a larger allowance because, measured on an idle stack, it writes about 300 times more than the API.

  6. Rollback is one commit SHA. Every green commit is published under its own SHA and nothing is tagged latest, so running an older version is the same command with an older tag.

  7. The proxy never caches a container's address. It re-resolves service names every 10 seconds, so recreating the API or the web container does not leave the proxy pointing at a dead address.

What it does not do

More