Install WordPress on a VPS with Docker

Tested · 6.x · 2026-11-21Beginner · ~10 min hands-on · 3 min readLine B

This page contains affiliate links. If you buy through them we may earn a commission — it never affects our rankings or scores. How we make money

Watch on YouTube ↗ — if the player asks you to sign in, YouTube is flagging your network; the video itself is public and plays on YouTube directly.

On this page

A production-shaped WordPress stack — Docker Compose, MariaDB, a real domain, and a free Let's Encrypt certificate — on a $3 VPS. Every command below is exactly what the video shows.

What you need

  • A server running Ubuntu 24.04 (this guide uses a 1-core / 2 GB VPS; any Ubuntu VPS or a spare machine at home works the same)
  • A domain name with an A record pointing at the server's IP (we use demo.deploysaga.com)
  • About 10 minutes

1. Update the server

ssh your-user@your-server-ip
sudo apt-get update

2. Install Docker (official repository)

Use Docker's own apt repository — the distro package is usually outdated.

sudo apt-get install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo docker run hello-world

If hello-world prints its welcome message, the daemon works.

3. The Compose file

mkdir -p ~/wordpress/certs && cd ~/wordpress
nano docker-compose.yml
services:
  db:
    image: mariadb:11
    restart: unless-stopped
    environment:
      MARIADB_DATABASE: wordpress
      MARIADB_USER: wpuser
      MARIADB_PASSWORD: use-your-own-db-password
      MARIADB_ROOT_PASSWORD: use-your-own-root-password
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    restart: unless-stopped
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: use-your-own-db-password
      WORDPRESS_DB_NAME: wordpress
    ports:
      - "8080:80"
    volumes:
      - wp_data:/var/www/html

volumes:
  db_data:
  wp_data:

Start it and check that WordPress answers locally:

sudo docker compose up -d
curl -sI http://localhost:8080

A 302 redirect to the installer means the stack works. Right now it is only reachable by IP and port, without encryption — time for the domain and certificate.

4. Get a certificate (Let's Encrypt, DNS challenge)

The DNS challenge proves domain ownership with a TXT record, so the server never needs to be publicly reachable for validation.

sudo apt-get install -y certbot
sudo certbot certonly --manual --preferred-challenges dns -d demo.deploysaga.com --agree-tos -m you@example.com --no-eff-email

Certbot shows a record name (_acme-challenge.demo.deploysaga.com) and a value. Add that TXT record at your DNS provider, wait a few seconds, verify it resolves, then press Enter. (On Cloudflare, the certbot-dns-cloudflare plugin can automate this step.)

Copy the issued files next to the project:

sudo cp /etc/letsencrypt/live/demo.deploysaga.com/fullchain.pem /etc/letsencrypt/live/demo.deploysaga.com/privkey.pem ~/wordpress/certs/

5. Add Caddy as the reverse proxy

Caddy's whole config is three lines. Create ~/wordpress/Caddyfile:

demo.deploysaga.com {
    tls /certs/fullchain.pem /certs/privkey.pem
    reverse_proxy wordpress:80
}

Then update docker-compose.yml: remove the 8080:80 port mapping from WordPress, add the address config below, and add the Caddy service.

  wordpress:
    # ... same as before, but WITHOUT the ports: block, and WITH:
    environment:
      WORDPRESS_CONFIG_EXTRA: |
        define('WP_HOME', 'https://demo.deploysaga.com');
        define('WP_SITEURL', 'https://demo.deploysaga.com');
        if (isset($$_SERVER['HTTP_X_FORWARDED_PROTO']) && $$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') { $$_SERVER['HTTPS'] = 'on'; }

  caddy:
    image: caddy:2
    restart: unless-stopped
    depends_on:
      - wordpress
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./certs:/certs:ro
      - caddy_data:/data

volumes:
  db_data:
  wp_data:
  caddy_data:

Two details that matter:

  • WP_HOME / WP_SITEURL tell WordPress its real address is the HTTPS domain. Without them you get redirect loops behind the proxy.
  • The double dollar sign. Docker Compose interpolates $ in environment values, so $_SERVER must be written as $$_SERVER in the Compose file — otherwise the variable is silently eaten and the HTTPS detection never runs.

Restart and verify:

sudo docker compose up -d
curl -sI https://demo.deploysaga.com

HTTP/2 200 (or a 302 to the installer on a fresh site) means you are live.

6. Run the WordPress installer

Open https://demo.deploysaga.com in a browser. Pick a site title, an admin username, a strong password (not the demo ones), and your email — Install — done. You now have a production-shaped WordPress: containerized, on a real domain, behind a real certificate.

Where to get the server

The VPS in the video is a 1-slice InterServer VPS (1 core, 2 GB RAM, $3/month): InterServer via DeploySaga. Any other Ubuntu 24.04 VPS — or a spare machine at home — runs the exact same steps.

Next in this series: install n8n on the same server and automate your first workflow.

DeploySaga deskEvery step run hands-on from a clean install — no vendor screenshots, no copied docs.