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.
Contents
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
Step 2: Create a docker-compose.yml
File
Inside your project folder, create a file named docker-compose.yml
:
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:
-
WordPress will be available at: http://localhost:8080
-
phpMyAdmin will be available at: http://localhost:8081
Step 4: Install WordPress
-
Open http://localhost:8080 in your browser.
-
Choose your language.
-
Enter site details (title, username, password, email).
-
Complete the installation.
You now have a fully working Dockerized WordPress site! π
Step 5: Manage Your Containers
-
Stop containers:
-
Restart containers:
-
Check logs:
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.
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
).