DEV Community

Shashank Morappanavar
Shashank Morappanavar

Posted on

πŸš€ How to Deploy Any WordPress Web App Using Docker

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
Enter fullscreen mode Exit fullscreen mode

🐳 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
Enter fullscreen mode Exit fullscreen mode

🧩 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:
Enter fullscreen mode Exit fullscreen mode

πŸš€ Launch WordPress
Run this to build and start the containers:

docker-compose up --build
Enter fullscreen mode Exit fullscreen mode

Your site will be available at:
http://ec2-ip/wordpress

Top comments (0)