If you're a developer or WordPress enthusiast looking to containerize your website for portability and ease of deployment, this step-by-step guide will walk you through the entire process—from setup to containerization.
📦 Prerequisites
- Docker & Docker Compose installed
- A basic WordPress website (with custom plugins/themes if any)
- (Optional) Exported WordPress content in
.xml
format
📁 Project Structure
Start by creating a working directory:
wordpress-docker/
├── Dockerfile
├── wp-content/
│ └── plugins/
│ └── hello-world-sample/
├── wp-data.xml # (optional) exported WordPress content
└── docker-compose.yml
🐳 Dockerfile for WordPress
Create a Dockerfile to extend the official WordPress image and include your custom plugin:
FROM wordpress:6.5-php8.1-apache
##Copy your plugin into the WordPress plugin directory
COPY wp-content/plugins/hello-world-sample /var/www/html/wp-content/plugins/hello-world-sample
##Fix permissions (optional)
RUN chown -R www-data:www-data /var/www/html/wp-content/plugins/hello-world-sample
🧩 Docker Compose File
Create docker-compose.yml to set up both WordPress and MySQL:
version: '3.8'
services:
wordpress:
build: .
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wp_user
WORDPRESS_DB_PASSWORD: wp_pass
WORDPRESS_DB_NAME: wp_db
volumes:
- wordpress_data:/var/www/html
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: wp_db
MYSQL_USER: wp_user
MYSQL_PASSWORD: wp_pass
MYSQL_ROOT_PASSWORD: rootpass
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data:
🚀 Launch WordPress
Run this to build and start the containers:
docker-compose up --build
Your site will be available at:
http://ec2-ip/wordpress