This guide will walk through hosting a WordPress site on an Ubuntu server using Docker Compose.

Step 1: Create a directory to hold your Docker Compose files:

Step 2: 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.
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:
