WordPress with Docker Compose
Run WordPress production-ready on your own server – with Docker Compose, MariaDB and an optional Nginx reverse proxy.
Prerequisites
- Ubuntu 22.04 or 24.04 server with root access
- At least 1 GB RAM (2 GB recommended)
- Docker and Docker Compose installed
- A domain with a DNS A record (for SSL)
Step 1: Create a project directory
mkdir -p ~/wordpress && cd ~/wordpress
Step 2: Create docker-compose.yml
# docker-compose.yml
services:
db:
image: mariadb:11
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: geheim_root_pw_aendern
MYSQL_DATABASE: wordpress
MYSQL_USER: wp_user
MYSQL_PASSWORD: geheim_wp_pw_aendern
volumes:
- db_data:/var/lib/mysql
wordpress:
image: wordpress:latest
restart: unless-stopped
depends_on:
- db
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wp_user
WORDPRESS_DB_PASSWORD: geheim_wp_pw_aendern
WORDPRESS_DB_NAME: wordpress
volumes:
- wp_data:/var/www/html
volumes:
db_data:
wp_data:Security: Replace all password placeholders before the first start:
MYSQL_ROOT_PASSWORD, MYSQL_PASSWORD and WORDPRESS_DB_PASSWORD. MYSQL_PASSWORD and WORDPRESS_DB_PASSWORD must be identical (as must MYSQL_USER/WORDPRESS_DB_USER and MYSQL_DATABASE/WORDPRESS_DB_NAME), otherwise WordPress cannot connect to the database. MariaDB only applies these values on the very first start – if you change them later, you have to change the password inside the database as well or recreate the db_data volume (this deletes the database). In production, use a .env file instead of hard-coded values.Step 3: Start the containers
docker compose up -d # Check the status docker compose ps # View the logs docker compose logs -f wordpress
Open http://YOUR-IP:8080 in your browser. You will see the WordPress installation wizard.
Step 4: Secure it with a .env file
# .env MYSQL_ROOT_PASSWORD=dein_sicheres_root_passwort MYSQL_PASSWORD=dein_sicheres_wp_passwort
Then use ${MYSQL_ROOT_PASSWORD} in docker-compose.yml instead of the plain-text root password, and ${MYSQL_PASSWORD} for both MYSQL_PASSWORD and WORDPRESS_DB_PASSWORD – that way the two values always match.
Step 5: Set up backups
# Database backup docker compose exec db mysqldump -u root -p wordpress > backup.sql # Back up the WordPress files docker compose cp wordpress:/var/www/html ./wp-backup
WordPress needs a reliable server
Our KVM servers with SSD storage and guaranteed resources keep your load times fast.
Order a server