How to Install WordPress With Docker

Docker has revolutionized the way we deploy applications. If you’re a WordPress user or developer, using Docker can make your workflow simpler, faster, and more consistent across environments. Instead of manually installing WordPress, Apache/Nginx, PHP, and MySQL, Docker lets you package all dependencies into containers that can run anywhere.

In this guide, you’ll learn how to install WordPress using Docker step-by-step, configure it for development or production, and manage updates efficiently.


Why Use Docker for WordPress?

Using Docker provides several advantages:

  1. Consistency Across Environments – Your site runs the same locally and on your server.
  2. Isolation – WordPress and its dependencies are isolated from the server, reducing conflicts.
  3. Easier Backup & Restore – Docker volumes store data separately.
  4. Portability – Move your container from local to cloud without reinstalling.
  5. Version Control – You can pin WordPress, PHP, and MySQL versions easily.

Prerequisites

Before starting, ensure you have:

  • A server or local machine with Docker installed (Linux, Windows, or Mac)
  • Basic familiarity with command-line operations
  • At least 2GB RAM for smoother container performance
  • Optional: Docker Compose installed for multi-container management

Step 1: Install Docker and Docker Compose

For Ubuntu:

sudo apt update
sudo apt install docker.io docker-compose -y
sudo systemctl enable docker
sudo systemctl start docker
docker --version
docker-compose --version

Verify Docker runs correctly:

sudo docker run hello-world

This should print a success message.


Step 2: Create a Project Directory

Choose a directory for your WordPress project:

mkdir wordpress-docker
cd wordpress-docker

This will contain:

  • docker-compose.yml file
  • Persistent volumes for WordPress and MySQL

Step 3: Create docker-compose.yml

Create a docker-compose.yml file in your project folder:

version: '3.8'

services:
  db:
    image: mysql:8.0
    container_name: wordpress_db
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: wppassword
      MYSQL_ROOT_PASSWORD: rootpassword
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    container_name: wordpress_app
    depends_on:
      - db
    ports:
      - "8080:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: wppassword
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wordpress_data:/var/www/html

volumes:
  db_data:
  wordpress_data:

Explanation:

  • db container: MySQL database
  • wordpress container: WordPress site
  • volumes: Keep data persistent even if containers are removed
  • Port mapping 8080:80 allows local access at http://localhost:8080

Step 4: Start Containers

Run:

docker-compose up -d
  • -d runs containers in detached mode
  • Check containers:
docker ps

You should see WordPress and MySQL containers running.


Step 5: Access WordPress

Open a browser and go to:

http://localhost:8080

Complete the WordPress installation wizard:

  • Choose language
  • Site title
  • Admin username/password
  • Email

Your WordPress site is now live inside Docker.


Step 6: Managing Containers

Stop containers:

docker-compose down

Restart containers:

docker-compose up -d

View logs:

docker-compose logs -f

Step 7: Updating WordPress

To update WordPress:

  1. Pull the latest image:
docker pull wordpress:latest
  1. Stop and remove the container:
docker-compose down
  1. Start with the new image:
docker-compose up -d

Your data remains safe in volumes.


Step 8: Optional – Using phpMyAdmin

Add phpMyAdmin to manage MySQL visually:

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

Access via:

http://localhost:8081

Step 9: Security Tips

  • Never expose MySQL root password publicly
  • Use strong admin passwords for WordPress
  • Regularly backup volumes

Conclusion

Installing WordPress with Docker simplifies deployment, makes your site portable and isolated, and allows faster development. Once set up, you can easily scale or migrate without downtime. For developers, this is a must-learn skill in modern WordPress hosting.


Next Step: You can now combine Docker with NGINX reverse proxy, SSL, and caching for production-grade sites.

Similar Posts

Leave a Reply

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