Installing WordPress with Docker Compose (Ubuntu)
📘 What Will You Learn in This Guide?
In this guide, we will install WordPress with a modern and manageable architecture using Docker Compose.
MySQL, WordPress and Nginx will run in separate containers.
SSL certificates will be automatically obtained and renewed with Let's Encrypt.
🧠 Technical Summary
This guide explains how to install WordPress with Docker Compose on Ubuntu.
The aim is to eliminate the classic LAMP/LEMP installation confusion.
The setup includes SSL, Nginx and automatic certificate renewal.
Preliminary Preparations
Before you start, you should have the following ready:
- A server with Ubuntu 20.04 or 22.04
- Docker and Docker Compose must be installed
- Domain name DNS A records must be directed to the server IP
- Ports 80 and 443 must be open
1. Defining Nginx Configuration
First create the project directory:
mkdir wordpress && cd wordpress
- This command creates the WordPress project folder.
mkdir nginx-conf
nano nginx-conf/nginx.conf
- This file contains the Nginx configuration.
server {
listen 80;
server_name siteadresiniz.com www.siteadresiniz.com;
root /var/www/html;
index index.php index.html;
location ~ /.well-known/acme-challenge {
allow all;
root /var/www/html;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass wordpress:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
This structure is required for SSL authentication and WordPress.
2. Defining Environment Variables (.env)
- Sensitive information should be kept in .env file.
nano .env
MYSQL_ROOT_PASSWORD=guclu_root_sifre
MYSQL_USER=wp_kullanici
MYSQL_PASSWORD=guclu_wp_sifre
- This information is used for database access.
nano .gitignore
.env
- This setting prevents confidential information from being added to the repo.
3. Defining Docker Compose Services
nano docker-compose.yml
- MySQL Service
services:
db:
image: mysql:8.0
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress
volumes:
- dbdata:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
- This service runs the WordPress database.
2.1 WordPress Service
wordpress:
image: wordpress:php8.1-fpm
depends_on:
- db
env_file: .env
environment:
- WORDPRESS_DB_HOST=db:3306
- WORDPRESS_DB_USER=${MYSQL_USER}
- WORDPRESS_DB_PASSWORD=${MYSQL_PASSWORD}
- WORDPRESS_DB_NAME=wordpress
volumes:
- wordpress:/var/www/html
This service runs the WordPress application.
- Nginx Service
webserver:
image: nginx:alpine
depends_on:
- wordpress
ports:
- "80:80"
volumes:
- wordpress:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
Bu servis HTTP trafiğini yönetir.
3.1 Certbot Service (SSL)
certbot:
image: certbot/certbot
volumes:
- wordpress:/var/www/html
- certbot-etc:/etc/letsencrypt
command: certonly --webroot --webroot-path=/var/www/html --email admin@siteadresiniz.com --agree-tos --no-eff-email --staging -d siteadresiniz.com -d www.siteadresiniz.com
- The --staging parameter is for testing purposes and maintains limits.
4. Starting Containers
docker-compose up -d
- This command starts all services.
docker-compose ps
- All services must be in Up state.
5. HTTPS Configuration
curl -sSLo nginx-conf/options-ssl-nginx.conf https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf
- This file downloads the recommended SSL settings.
- Nginx configuration is updated with HTTPS support:
listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/siteadresiniz.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/siteadresiniz.com/privkey.pem;
6. WordPress Installation
- From the browser, go to the following address:
https://siteadresiniz.com
- Select the language and enter administrator information.
7. Automatic SSL Renewal (Cron)
nano ssl_renew.sh
#!/bin/bash
docker-compose run certbot renew && docker-compose kill -s SIGHUP webserver
- This script renews certificates.
chmod +x ssl_renew.sh
sudo crontab -e
0 12 * * * /home/kullanici/wordpress/ssl_renew.sh >> /var/log/cron.log 2>&1
This task checks certificates daily.
❓ Frequently Asked Questions
1. Why should Docker Compose be preferred? Installation is standard and easy to manage.
2. Will the data be deleted? No, the volume structure preserves the data.
3. Why is mysql_native_password necessary? It is required for PHP compatibility.
4. Why is staging used? To avoid SSL limits.
🚀 Result
Installing WordPress with Docker Compose is fast and secure. With SSL and automatic renewal, maintenance burden is reduced.
👉 You can install this structure on GenixNode in minutes.

