Skip to main content

[Ubuntu/Debian] WordPress installation with Docker Compose

Updated over a week ago

WordPress is one of the most popular platforms for creating websites and blogs. This content management system (CMS) lets you manage key aspects of your site - such as content - without any programming knowledge.

If you need to set up multiple hosting environments or manage server-side tasks, Docker Compose can simplify the installation process. With a single deployment command, it saves significant time and effort.

What is Docker and Docker Compose?

Docker is a tool for creating, deploying, and running applications inside containers.
Docker Compose is a companion tool that helps define and manage multi-container applications.

  • Docker handles single containers.

  • Docker Compose handles applications made up of multiple containers.

How to Install WordPress with Docker

You’ll deploy two containers:

  1. A WordPress container

  2. A MariaDB container to store WordPress data

Docker Compose will link them together and manage their networking.

Requirements:

  • Docker installed

  • Docker Compose installed

  • A docker-compose.yml file

1. Install Docker

Supported systems: Ubuntu 22.04 / 24.04 or Debian 12.

Note: The old apt-key method is deprecated. This guide uses the keyring method.

Update your package list:

sudo apt update

Install dependencies:

sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg

Add Docker’s GPG key:

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg

Add Docker’s repository:

echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \ $(. /etc/os-release; echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker CE:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Add your user to the Docker group:

sudo usermod -aG docker $USER

(Reconnect your SSH session for changes to take effect.)

Verify installation:

sudo systemctl
status docker docker run hello-world

2. Docker Compose

Docker Compose is now included in the Docker CLI. Use:

docker compose version

No separate installation is required.

3. Configure WordPress with Docker Compose

Create a WordPress directory and move into it:

mkdir ~/wordpress/ 
cd ~/wordpress/

Create a docker-compose.yml file:

nano docker-compose.yml

Add the following:

services:

db:

environment:

MARIADB_DATABASE: wordpress

MARIADB_PASSWORD: password

MARIADB_ROOT_PASSWORD: password

MARIADB_USER: wordpress

image: "mariadb:11"

restart: always

volumes:

- "db_data:/var/lib/mysql"

wordpress:

depends_on:

- db

environment:

WORDPRESS_DB_HOST: "db:3306"

WORDPRESS_DB_NAME: wordpress

WORDPRESS_DB_PASSWORD: password

WORDPRESS_DB_USER: wordpress

image: "wordpress:latest"

ports:

- "80:80"

restart: always

version: "3.9"

volumes:

db_data: {}

Important: Replace the default passwords (MARIADB_PASSWORD, WORDPRESS_DB_PASSWORD, MARIADB_ROOT_PASSWORD) with secure values.

4. Start WordPress

Run the following command inside the WordPress directory:

docker compose up -d

If everything is correct, Docker Compose will create and start the containers.

If you see an error like:

yaml.scanner.ScannerError: mapping values are not allowed here

your YAML file has formatting issues. Use yamllint.com to validate it.

5. Test WordPress

Open your server’s hostname or IP address in a browser:

http://<your-server-ip>/wp-admin/install.php

You’ll be redirected to the WordPress installation page.

6. Additional Notes

If your server OS is not Ubuntu or Debian, refer to the official Docker documentation for installation steps tailored to your system.

Did this answer your question?