This guide will assume you already have a working docker & docker-compose installation. If not you can follow up our Guide to install Docker and Docker Compose.

Create tree directory

mkdir -p /opt/wordpress-local

Populate the docker-compose configuration file. WORDPRESS_DB_PASSWORD & MYSQL_PASSWORD must be the same in order to allow WordPress image to connect to the MySQL one.
I change the port too, as my 80 is already taken by another application.

version: '3.3'

services:
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     volumes:
       - wordpress_files:/var/www/html
     ports:
       - "18000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: #######

   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: #######
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: #######
volumes:
    wordpress_files:
    db_data:

Start the Docker container

sudo docker-compose up -d

Verify the image is correctly running with:

sudo docker container ls -a

Open a browser to the url http://127.0.0.1:18000, and select installation language.

Installation is now finished.

You can experience some issue when browsing from another IP address, this will be due to the “WordPress Address” & “Site Address” parameters set up in the Settings -> General menu.

Adapt it with an IP/hostname if it remains only on a local network, or with FQDN (yoursite.com) if it it destined to production environment.