Raddy Website Design & Development Tutorials | RaddyDev

How to Run WordPress Locally with Docker (Easy Setup Guide!) MariaDb, PhpMyAdmin

By Raddy in WordPress ·

Learn how to run WordPress locally using Docker, MariaDB, and phpMyAdmin – the modern and hassle-free way to set up a WordPress development environment without installing everything manually. Perfect for developers, freelancers, or anyone wanting to build WordPress projects locally.

Setting Up WordPress with Docker: A Complete Guide

Prerequisites

Before you begin, download and install Docker Desktop for your operating system.

Project Setup

Step 1: Create Your Project Structure

Create a new project folder and add two configuration files:

docker-compose.yml – Defines your Docker services

.env – Contains your environment variables

Step 2: Configure Environment Variables

Create a .env file in your project root with the following configuration:

# Database Configuration
DB_ROOT_PASSWORD=password
DB_NAME=wordpress
DB_USER=root
DB_PASSWORD=password

# WordPress Configuration
WP_PORT=8080

# phpMyAdmin Configuration
PMA_PORT=8081

Important: Change the default passwords before deploying to production!

Step 3: Set Up Docker Compose

Create a docker-compose.yml file with the following configuration:

version: '3.8'

services:
  db:
    image: mariadb:latest
    container_name: wordpress_db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - wordpress_network

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    container_name: wordpress_site
    restart: unless-stopped
    ports:
      - "${WP_PORT}:80"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: ${DB_NAME}
      WORDPRESS_DB_USER: ${DB_USER}
      WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}
    volumes:
      - wp_data:/var/www/html
    networks:
      - wordpress_network

  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin:latest
    container_name: wordpress_phpmyadmin
    restart: unless-stopped
    ports:
      - "${PMA_PORT}:80"
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
    networks:
      - wordpress_network

volumes:
  db_data:
  wp_data:

networks:
  wordpress_network:
    driver: bridge

Launch Your WordPress Site

Navigate to your project folder in the terminal and run:

docker-compose up -d

That’s it! Your WordPress environment is now running.

Access Your Services

Once the containers are up and running, you can access:

Your website files can be found inside: \\wsl.localhost\docker-desktop\tmp\docker-desktop-root\var\lib\docker\volumes\YOUR_WEBSITE_wp_data_data\

What’s Included

This setup provides you with:

  • MariaDB: A robust database server for WordPress
  • WordPress: The latest version of WordPress, ready to configure
  • phpMyAdmin: A web interface for managing your database

All services are connected through a dedicated Docker network and use persistent volumes to store your data safely.

Leave a Reply

Your email address will not be published. Required fields are marked *