Installing WordPress with Docker Compose: Step-by-Step Guide
What Will You Learn in This Guide?
In this guide, you will learn how to stand up the WordPress infrastructure with a single configuration using Docker Compose.
- Running WordPress, MySQL and Nginx services with container architecture
- Get a free SSL certificate with Let's Encrypt
- Provide uninterrupted HTTPS by automatically renewing SSL certificates
Technical Summary
This guide explains how to install WordPress using Docker Compose on Ubuntu.
Instead of manual LAMP/LEMP installations; The database, application and web server are run in isolation through containers.
The installation process includes these steps:
- Nginx web server configuration
- Managing environment variables with the
.envfile - Obtaining an SSL certificate
- Automating the certificate renewal process
Step 1: Nginx Web Server Configuration
First, create the directory that will host the project and open the Nginx configuration file:
mkdir wordpress && cd wordpress
mkdir nginx-conf && nano nginx-conf/nginx.conf
- These commands create the project folder and open the Nginx settings file for editing.
This configuration:
-
Defines the domain name
-
Redirects PHP requests to the WordPress container
-
Meets SSL verification requests
Step 2: Defining Environment Variables
- Increase security by keeping sensitive data such as database information in the .env file:
nano .env
Sample content:
MYSQL_ROOT_PASSWORD=parolaniz
MYSQL_USER=wp_kullanici
MYSQL_PASSWORD=wp_sifre
⚠️ Important:
- Be sure to add the .env file into .gitignore.
- In this way, your passwords will not be shared accidentally.
Step 3: Starting Services with Docker Compose
- The following services are defined in the docker-compose.yml file:
-
MySQL (db)
-
WordPress (PHP-FPM)
-
Nginx (webserver)
nano docker-compose.yml
- This file:
-
Select the Docker images to be used
-
How the services will communicate with each other
-
Determines volume and network structures.
To initialize the entire infrastructure:
docker-compose up -d
- This command publishes the WordPress environment in one go.
Step 4: SSL Certificate and Automatic Renewal
- By obtaining a free SSL certificate with Let's Encrypt, your site is published over HTTPS.
- First a staging certificate is created, then a live certificate is created.
Create a script for automatic renewal of certificates:
nano ssl_renew.sh
chmod +x ssl_renew.sh
- This script:
-
Checks the certificate duration
-
Automatically renews if necessary
- Reloads Nginx without interruption
Add to cron:
sudo crontab -e
- Add to the end of the file:
0 12 * * * /home/kullanici/wordpress/ssl_renew.sh
- This task performs an automatic certificate check every day.
Frequently Asked Questions (FAQ)
1. If I stop the containers, will my data be deleted? No. Thanks to the volume structure, data is permanent on the server disk.
2. Can I use Apache instead of Nginx? Yes, but Nginx is lighter and more performant in Docker environments.
3. Why use PHP-FPM for WordPress? Nginx cannot run PHP directly. PHP-FPM takes over this task.
4. How do I connect my domain? Simply add an A record to the server IP address from the domain panel.
| Problem | Possible Cause | Solution |
|---|---|---|
| Connection refused | Firewall off | Open ports 80 and 443 |
| Database error | .env information is incorrect | Check information |
| Failed to obtain SSL | DNS not propagated | Verify domain redirect |
Result
With this guide, you have established a secure, portable and high-performance WordPress infrastructure on Docker.
🚀 You can go live this structure within minutes on the GenixNode infrastructure.

