Support Online
Skip to main content

Installing WordPress with Docker Compose: Comprehensive Guide

Keyword: Docker Compose WordPress Installation

📘 What Will You Learn in This Guide?

In this guide, you will set up a modern WordPress infrastructure using Docker Compose without dealing with classic LAMP or LEMP installations.
You will integrate the MySQL database, Nginx web server, and Let's Encrypt SSL certificates with the container architecture.
In the last stage, you will ensure automatic renewal of SSL certificates.


🔧 Preliminary Preparations

The following should be ready before continuing:

  • A virtual server with Ubuntu installed (GenixNode recommended)
  • Docker and Docker Compose must be installed
  • Domain name and DNS A records must be directed to the server IP
  • Ports 80 and 443 must be open

1ï¸âƒ£ Defining Web Server (Nginx) Configuration

  1. In the first stage, we create the project directory and prepare the Nginx configuration.
    At this stage, SSL is not activated yet.
mkdir wordpress && cd wordpress
  • This command creates the main project directory for WordPress.

mkdir nginx-conf
  • Nginx configuration files are kept in this directory.


nano nginx-conf/nginx.conf
  • This command opens the Nginx configuration file.

server {
listen 80;
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$is_args$args;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass wordpress:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~ /\.ht {
deny all;
}
}

This structure redirects PHP requests to the WordPress container.

2ï¸âƒ£ Defining Environment Variables (.env)

  • .env file is used to securely store database passwords.

nano .env

This file holds confidential data.


MYSQL_ROOT_PASSWORD=guclu_root_sifresi
MYSQL_USER=wp_kullanici
MYSQL_PASSWORD=wp_db_sifresi
  • This information is used for MySQL and WordPress connection.

  1. Exclude the .env file from version control:

nano .gitignore

.env

nano .dockerignore

.env
.git

3ï¸âƒ£ Creating Docker Compose Services

  1. We define all services in one file.

nano docker-compose.yml

This file manages all containers.


version: '3'

services:
db:
image: mysql:8.0
container_name: db
restart: unless-stopped
env_file: .env
environment:
- MYSQL_DATABASE=wordpress
volumes:
- dbdata:/var/lib/mysql
command: --default-authentication-plugin=mysql_native_password
networks:
- app-network

wordpress:
image: wordpress:php8.2-fpm
container_name: wordpress
depends_on:
- db
restart: unless-stopped
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
networks:
- app-network

webserver:
image: nginx:alpine
container_name: webserver
depends_on:
- wordpress
restart: unless-stopped
ports:
- "80:80"
volumes:
- wordpress:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
networks:
- app-network

certbot:
image: certbot/certbot
container_name: certbot
depends_on:
- webserver
volumes:
- certbot-etc:/etc/letsencrypt
- wordpress:/var/www/html
command: certonly --webroot --webroot-path=/var/www/html \
--email eposta@siteadresiniz.com --agree-tos --no-eff-email --staging \
-d siteadresiniz.com -d www.siteadresiniz.com

volumes:
dbdata:
wordpress:
certbot-etc:

networks:
app-network:
driver: bridge

The --staging parameter obtains the test certificate and maintains the limits.


4ï¸âƒ£ Obtaining SSL Certificate


docker-compose up -d
  • All services are started in the background.

docker-compose logs certbot

The "Congratulations" message indicates that the certificate has been received.

If successful, --staging is removed and the real certificate is obtained:


docker-compose up --force-recreate --no-deps certbot

5ï¸âƒ£ Completing HTTPS Configuration

  • Nginx configuration is updated to support HTTPS.
  • HTTP traffic is automatically redirected to HTTPS.
  1. This file downloads recommended SSL security settings.

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

  1. Activate port 443:

ports:
- "80:80"
- "443:443"

docker-compose up -d --force-recreate --no-deps webserver

6ï¸âƒ£ Completing the WordPress Installation from the Web Interface

  1. From the browser, go to:

https://siteadresiniz.com
  1. Select your language, enter administrative information and complete the installation.

7ï¸âƒ£ Automatic SSL Certificate Renewal


nano ssl_renew.sh


#!/bin/bash
cd /home/kullaniciadi/wordpress
docker-compose run certbot renew && docker-compose kill -s SIGHUP webserver


chmod +x ssl_renew.sh


sudo crontab -e


0 12 * * * /home/kullaniciadi/wordpress/ssl_renew.sh >> /var/log/cron.log 2>&1

Certificates are automatically checked every day.


â“ Frequently Asked Questions (FAQ)

1. Why should Docker Compose be preferred? It accelerates installation and standardizes the infrastructure.

2. Will the data be deleted? No, it is permanent because Docker volume is used.

3. Why is mysql_native_password necessary? It is required for WordPress' MySQL 8 compatibility.

4. Why get SSL with staging first? To avoid Let's Encrypt limits.

ðŸ Conclusion With this guide, you have set up a secure and scalable WordPress infrastructure using Docker Compose. Nginx, MySQL and SSL are completely container-based. Uninterrupted security is ensured with automatically renewed certificates.

You can implement this structure on GenixNode servers in minutes.