Containers & Infrastructure

Inception: Dockerized NGINX, WordPress & MariaDB Stack

A three-container web stack, NGINX with TLS, WordPress on PHP-FPM, and MariaDB, built from Debian images with Docker Compose and persistent volumes.

Last updated:

Inception: Dockerized NGINX, WordPress & MariaDB Stack

Introduction

Inception is a 42 system administration project: build a small production-style web infrastructure entirely from your own Docker images. Instead of pulling ready-made nginx, wordpress, or mariadb images, every service is built from debian:bullseye with its own Dockerfile and entrypoint script, then orchestrated with Docker Compose.

The result is a WordPress site served over HTTPS only, with its database and files stored on the host so they survive container rebuilds, and a Makefile that brings the whole stack up, down, or back to a clean state.

The problem

A web application set up by hand on one machine is hard to reproduce: packages, configuration files, credentials, and data all live in the same place, and rebuilding the server means repeating every step from memory. Running the web server, the application runtime, and the database together also makes it hard to change or restart one part without affecting the others.

The goal was to split the stack into isolated services with clear boundaries, configure them entirely from code and environment variables, and keep the data safe across rebuilds.

Architecture

NGINX is the only entry point and listens on port 443 with TLS 1.2 and 1.3. It serves static files and forwards PHP requests over FastCGI to the WordPress container, where PHP-FPM 7.4 listens on port 9000. WordPress connects to MariaDB on port 3306. The three containers share a private Docker bridge network, so only the HTTPS port is exposed to the host.

Two named volumes are bound to directories on the host: one for the WordPress files, shared by NGINX and WordPress, and one for the MariaDB data directory. Credentials, the domain name, and WordPress users are injected through an env file, and every container restarts automatically if it stops.

Implementation decisions

Images built from Debian, not pulled
Each service is built from debian:bullseye with only the packages it needs. Every dependency is explicit, and it is clear exactly what each container contains instead of relying on an opaque official image.
Setup in entrypoint scripts
Each container runs a setup script before its main process. NGINX generates a self-signed certificate only if none exists, WordPress is downloaded and configured with WP-CLI only if wp-config.php is missing, and MariaDB creates the database and its user. The script then hands over with exec, so the real process runs in the foreground as PID 1 and receives signals correctly.
TLS at the edge, FastCGI inside
Only NGINX terminates HTTPS, restricted to TLS 1.2 and 1.3. PHP runs in its own container behind FastCGI, so the web server and the application runtime can be rebuilt independently.
Configuration from the environment
Database names, users, passwords, the site title, and the domain come from an env file, so the same images work for any deployment without editing a Dockerfile.
Volumes backed by host directories
Data lives in named volumes bound to host directories, so the database and site content survive docker compose down and image rebuilds and can be inspected or backed up directly from the host.

Technical challenges

  • Initializing MariaDB inside a container by starting the service temporarily to create the database and user, then running the server in the foreground
  • Ordering startup across containers, since WordPress needs the database for its install step and NGINX needs PHP-FPM to proxy requests
  • Switching PHP-FPM from a Unix socket to a TCP listener on port 9000 so NGINX can reach it from another container
  • Keeping containers alive without hacks such as infinite loops or tail -f, by running each main process in the foreground

Results

  • The whole stack builds and starts with one make command, and make re rebuilds it from a clean state
  • WordPress is reachable only over HTTPS, with PHP-FPM and the database hidden on the private network
  • Site content and the database survive container restarts and image rebuilds
  • Each service can be rebuilt, restarted, or inspected on its own, with dedicated log targets in the Makefile

Related case studies