Setting Up a WordPress Site and Nginx Proxy Manager with Docker Compose
This guide will walk through hosting a WordPress site and Nginx Proxy Manager on an Ubuntu server using Docker Compose.
Prerequisites
Before starting, ensure you have the following:
- An Ubuntu server (20.04 LTS or later)
- A user with sudo privileges
- Basic knowledge of Docker and Docker Compose
- Domain name pointing to your server’s IP address
Step 1: Install Docker and Docker Compose
First, install Docker and Docker Compose on your Ubuntu server.
1
2
sudo apt update
sudo apt install -y docker.io docker-compose
After installation, enable Docker to start on boot:
1
sudo systemctl enable docker
Verify the installation:
1
2
docker --version
docker-compose --version
Step 2: Set Up Your Directory Structure
Create a directory to hold your Docker Compose files:
1
2
mkdir -p ~/docker/wordpress
cd ~/docker/wordpress
Step 3: Create a Docker Compose File for WordPress and MySQL
In this directory, create a docker-compose.yml
file to define the WordPress and MySQL services.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
services:
db:
# We use a mariadb image which supports both amd64 & arm64 architecture
image: mariadb:10.6.4-focal
# If you really want to use MySQL, uncomment the following line
#image: mysql:8.0.27
command: '--default-authentication-plugin=mysql_native_password'
volumes:
- ./db_data:/var/lib/mysql
restart: unless-stopped
environment:
- MYSQL_ROOT_PASSWORD=somewordpress
- MYSQL_DATABASE=wordpress
- MYSQL_USER=wordpress
- MYSQL_PASSWORD=wordpress
expose:
- 3306
- 33060
wordpress:
image: wordpress:latest
volumes:
- ./wp_data:/var/www/html
ports:
- 8041:80
restart: always
environment:
- WORDPRESS_DB_HOST=db
- WORDPRESS_DB_USER=wordpress
- WORDPRESS_DB_PASSWORD=wordpress
- WORDPRESS_DB_NAME=wordpress
This file configures two services: wordpress
and db
(MySQL). It sets environment variables, maps volumes for persistent data storage, and establishes a network for communication between containers.
Step 4: Deploy WordPress and MySQL
Deploy the services using Docker Compose:
1
sudo docker-compose up -d
You can verify that the containers are running with:
1
sudo docker ps
Step 5: Set Up Nginx Proxy Manager
Now, let’s set up the Nginx Proxy Manager to manage your web traffic.
Create a directory for Nginx Proxy Manager:
1
2
mkdir -p ~/docker/nginx-proxy-manager
cd ~/docker/nginx-proxy-manager
Create another docker-compose.yml
file for Nginx Proxy Manager:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
version: '3.8'
services:
app:
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
ports:
- '80:80' # Public HTTP Port
- '443:443' # Public HTTPS Port
- '81:81' # Admin Web Port
# Add any other Stream port you want to expose
# - '21:21' # FTP
volumes:
- ./data:/data
- ./letsencrypt:/etc/letsencrypt
This configuration sets up Nginx Proxy Manager. It maps ports 80, 81, and 443, so you can access the web interface on port 81.
Deploy Nginx Proxy Manager:
1
sudo docker-compose up -d
Step 6: Configure Nginx Proxy Manager
Once the Nginx Proxy Manager is running, configure it to manage your WordPress site.
Step 7: Change Default Passwords and Update Docker Images
Change all default passwords. Use strong, unique passwords for the MySQL and Nginx Proxy Manager. Regularly update your Docker images and containers. Consider implementing a firewall like ufw to control access to your server.
Notes
By following these steps, you’ve successfully hosted a WordPress site with Nginx Proxy Manager on an Ubuntu server using Docker Compose. This setup not only simplifies the deployment process but also gives you flexibility in managing multiple sites with ease.