Managed web hosting platforms frequently trap site owners with introductory pricing that triples upon renewal while restricting SSH access, custom Nginx headers, and modern Redis object caching. Self-hosting your own website or technical blog on an Ubuntu 24.04 VPS using Docker Compose v2 gives you 100% infrastructure ownership for $5 per month.
By isolating your web application (WordPress or Ghost), database (MariaDB 11.4 LTS), and in-memory cache (Redis 7.4) inside dedicated Docker containers on an internal bridge network, just like our Self-Hosted Private ChatGPT (Open WebUI + Ollama) Docker Guide, you can spin up, migrate, or back up your entire publication in seconds.
wordpress:6.7-php8.3-apache, mariadb:11.4, redis:7.4-alpine & Host Nginx Reverse ProxyKey Takeaways
- Bind Containers Strictly to
127.0.0.1: Never publish container ports as8080:80(which bypasses UFW rules); always bind to127.0.0.1:8080:80so only your local TLS reverse proxy can reach the container. - Pin Specific Docker Image Tags: Pin major/minor versions (
mariadb:11.4,redis:7.4-alpine) rather than:latestto prevent unexpected database schema upgrades from breaking your site overnight. - Automate Offsite Restic Backups: Pair your Docker volumes with encrypted daily snapshots to Cloudflare R2 so you can recover from any hardware failure in five minutes.
Self-Hosted Publishing Stacks Compared: WordPress vs Ghost vs Hugo
Before deploying your docker-compose.yml stack, choose the publishing engine that matches your editorial workflow and server RAM budget. Compare the three most popular self-hosted web publishing architectures in 2026 below.
| Platform Stack | Runtime & Database | Idle Container RAM | Built-In Newsletters / Memberships? | Best Use Case |
|---|---|---|---|---|
| WordPress + Redis (Docker) | PHP 8.3-FPM + MariaDB 11.4 + Redis 7.4 | ~290 MB – 380 MB | Via Plugins | Full SEO control, custom Gutenberg schemas & large publications |
| Ghost v5.x (Docker) | Node.js + MySQL 8.0 | ~420 MB – 550 MB | Yes (Native Stripe & Email) | Independent newsletters and subscription publications |
| Hugo / Astro Static | Static HTML served by Nginx/Caddy | ~15 MB | External Embeds | Documentation sites and ultra-minimal developer blogs |
Step 1: Create the Production docker-compose.yml & .env Stack
Create a dedicated directory at /opt/webstack/, store your database credentials inside a 0600 .env file, and define an isolated backend_net bridge so MariaDB and Redis are completely invisible outside the Docker network.
sudo mkdir -p /opt/webstack && cd /opt/webstack
sudo nano /opt/webstack/docker-compose.yml
services:
db:
image: mariadb:11.4
container_name: web_mariadb
restart: unless-stopped
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --innodb-buffer-pool-size=256M
environment:
MARIADB_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
MARIADB_DATABASE: wp_production
MARIADB_USER: wp_user
MARIADB_PASSWORD: ${DB_USER_PASSWORD}
volumes:
- db_data:/var/lib/mysql
networks:
- backend_net
redis:
image: redis:7.4-alpine
container_name: web_redis
restart: unless-stopped
command: redis-server --maxmemory 128mb --maxmemory-policy allkeys-lru
networks:
- backend_net
wordpress:
image: wordpress:6.7-php8.3-apache
container_name: web_app
restart: unless-stopped
depends_on:
- db
- redis
ports:
- "127.0.0.1:8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: wp_production
WORDPRESS_DB_USER: wp_user
WORDPRESS_DB_PASSWORD: ${DB_USER_PASSWORD}
WORDPRESS_CONFIG_EXTRA: |
define('WP_REDIS_HOST', 'redis');
define('WP_REDIS_PORT', 6379);
define('DISALLOW_FILE_EDIT', true);
volumes:
- wp_html:/var/www/html
networks:
- backend_net
volumes:
db_data:
wp_html:
networks:
backend_net:
driver: bridge
Step 2: Launch the Stack, Terminate TLS & Automate Restic Backups
Start the stack in detached mode with docker compose up -d, point your host Nginx reverse proxy to http://127.0.0.1:8080, and secure the domain with a wildcard certificate and automated offsite backups.
# Launch the containerized website stack
sudo docker compose up -d
# Verify all three containers are running cleanly
sudo docker compose ps
- Terminate HTTPS with Let’s Encrypt: Configure your host Nginx reverse proxy to pass
X-Forwarded-Proto httpsto127.0.0.1:8080using a certificate from our Free Let’s Encrypt Wildcard SSL Guide. - Automate Daily Encrypted Backups: Never run a self-hosted database without automated offsite backups; adapt the exact cron script from our Vaultwarden Docker & Restic Cloudflare R2 Backup Guide to dump
mariadband snapshot/var/lib/docker/volumes/nightly.
Frequently Asked Questions (FAQ)
Is self-hosting a public website with Docker Compose safe?
Yes, provided you bind container ports strictly to localhost (127.0.0.1:8080:80) rather than 0.0.0.0, front the application with a hardened Nginx reverse proxy and Cloudflare WAF, and keep the database container isolated inside an internal Docker bridge network.
How do I fix an infinite ERR_TOO_MANY_REDIRECTS loop when running WordPress in Docker behind Nginx?
Ensure your host Nginx reverse proxy includes proxy_set_header X-Forwarded-Proto $scheme; in its location / block. The official WordPress Docker entrypoint automatically detects HTTP_X_FORWARDED_PROTO === 'https' and sets $_SERVER['HTTPS'] = 'on' to prevent redirect loops.

Comments
One response to “How to Self-Host a Website with Docker Compose on Ubuntu (2026)”
Article looks great!