Dockerized WordPress Setup for Beginners: Step-by-Step

Running WordPress on Docker is one of the easiest ways to create a portable, scalable, and consistent development or production environment.

Instead of installing PHP, MySQL, and Apache/Nginx manually, Docker allows you to containerize everything and run WordPress with just a few commands.

This guide will walk beginners through setting up a Dockerized WordPress environment using Docker and Docker Compose.


Why Use Docker for WordPress?

  • Quick Setup – Run WordPress in minutes without complex server configuration.

  • 🔒 Isolated Environment – Avoid conflicts with existing software on your machine.

  • 🔄 Portability – Move your entire setup between machines or cloud providers easily.

  • 📦 Scalability – Perfect for local development, testing, or even production.


Prerequisites

Before starting, make sure you have:

  • Docker Desktop installed (Windows, macOS, or Linux).

  • Docker Compose (comes with Docker Desktop by default).

  • Basic knowledge of command-line usage.


Step 1: Create a Project Directory

mkdir wordpress-docker
cd wordpress-docker

Step 2: Create a docker-compose.yml File

Inside your project folder, create a file named docker-compose.yml:

version: '3.9'

services:
  wordpress:
    image: wordpress:latest
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - ./wp-data:/var/www/html

  db:
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
      MYSQL_ROOT_PASSWORD: rootpassword
    volumes:
      - ./db-data:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - "8081:80"
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: rootpassword

Explanation:

  • WordPress container runs the WordPress site.
  • MySQL container stores your WordPress database.
  • phpMyAdmin container lets you manage the database via a web UI.

Step 3: Start the Containers

Run the following command inside your project folder:

docker-compose up -d

Step 4: Install WordPress

  1. Open http://localhost:8080 in your browser.

  2. Choose your language.

  3. Enter site details (title, username, password, email).

  4. Complete the installation.

You now have a fully working Dockerized WordPress site! 🎉


Step 5: Manage Your Containers

  • Stop containers:

    docker-compose down
  • Restart containers:

    docker-compose up -d
  • Check logs:

    docker-compose logs -f

Optional: Persistent Data

In the example above, WordPress files are stored in ./wp-data and database files in ./db-data. This ensures your content and database survive container restarts.


Best Practices for Beginners

  • Always use volumes to persist your data.

  • Keep your docker-compose.yml file under version control (e.g., Git).

  • Use different ports if running multiple WordPress instances.

  • For production, consider using Docker Swarm or Kubernetes.

READ :  Tema WordPress Premium Paling Populer

FAQ

1. Do I need coding skills to use Docker for WordPress?
Not much — basic command-line knowledge is enough.

2. Can I use Dockerized WordPress for production?
Yes, but it’s more common for local development. For production, add reverse proxy, SSL, and backups.

3. How do I access my WordPress database?
Use phpMyAdmin at http://localhost:8081 or connect via MySQL client.

4. Can I run multiple WordPress sites with Docker?
Yes, just create separate project directories with unique ports.

5. What happens if I delete the containers?
Your site will remain intact if you use volumes (wp-data, db-data).

Topic : Web | Tags : ,

Author : Andreas

Publisher konten yang berfokus pada topik spa massage, teknologi, bisnis online, dan digital. Ia aktif membuat artikel informatif yang membantu pembaca memahami tren terbaru secara lebih jelas dan mudah dipahami.

Editor : Team SEOSatu

Team SEOSatu bertanggung jawab atas proses penyuntingan, verifikasi, dan optimasi SEO pada setiap artikel. Tim memastikan konten yang dipublikasikan akurat, relevan, dan sesuai standar kualitas SEO.