WordPress Dockerized

Table of Contents

  1. Project Description
  2. Prerequisites
  3. Project Structure
  4. Quickstart
  5. Usage
  6. Environment Variables
  7. Checklist

Project Description

This repository provides a minimal and functional Docker-based setup for running WordPress locally. It uses the official WordPress and MariaDB containers via Docker Compose. All content is persisted using volumes, and the setup is ready to be deployed via Docker with a custom (optional) .env configuration.


Prerequisites

sudo apt update && sudo apt install -y docker.io docker-compose-v2

docker-compose-v2 installs the Compose V2 plugin, which is invoked as docker compose (with a space) — the syntax used throughout this document. The legacy docker-compose package (Compose V1, written in Python) is a different, unmaintained tool; Docker ended support for it after June 2023. If your distribution does not ship docker-compose-v2, install docker-compose-plugin from Docker's official repository instead.


Project Structure

wordpress/
├── docker-compose.yml
├── .env                # Environment variables (manually created)
├── .gitignore
└── README.md

Quickstart

  1. Install dependencies:
sudo apt update && sudo apt install -y docker.io docker-compose-v2 git
  1. Clone the repository:
git clone https://github.com/BenjaminTietz/wordpress-docker.git
cd wordpress-docker

  1. Generate and configure the .env file:

The environment file will be created automatically from template.env. Adjust the values to match your setup (optional):

cp template.env .env
nano .env (optional)

  1. Start the project:
docker compose up -d
  1. Access WordPress:

Visit in your browser:

http://localhost:8080

Or, if deployed on a remote VM:

http://<your-vm>:8080

Plain HTTP. Everything typed into /wp-admin — including the administrator password — and every session cookie afterwards travels the network unencrypted, so this form of access is only defensible on a host that is not reachable from the internet. For a publicly reachable VM: bind the published port to the loopback interface instead of every interface (host side of the ports: mapping, e.g. 127.0.0.1:8080:80), put a reverse proxy such as nginx, Caddy or Traefik in front of it, and let that proxy terminate TLS with a certificate from a public CA (Let's Encrypt). Port 8080 itself then never needs to be open in the firewall.

Usage

Environment Variables

All WordPress and MySQL credentials are configured via environment variables defined in the .env file:

Example:

WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_USER=wp_user
WORDPRESS_DB_PASSWORD=wp_pass
WORDPRESS_DB_HOST=db:3306

MARIADB_ROOT_PASSWORD=rootpass
MARIADB_DATABASE=wordpress
MARIADB_USER=wp_user
MARIADB_PASSWORD=wp_pass