← Back to list

How to Use Docker for WordPress Development

“Docker has transformed how we develop WordPress sites. No more ‘it works on my machine’ problems!” — Lead Developer, XYZ Agency

Pratik Bhatt in AddWeb Digital · 2025-03-25 12:33 · 300 claps · 3.1 min read
#docker #wordpress #php-mysql-database
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud 📰 · Journalism & News

How to Use Docker for WordPress Development

How to Use Docker for WordPress Development

How to Use Docker for WordPress Development

“Docker has transformed how we develop WordPress sites. No more ‘it works on my machine’ problems!” — Lead Developer, XYZ Agency

Table of Contents

  1. Introduction

  2. Why Use Docker for WordPress Development? Step 1: Install Docker Step 2: Create a docker-compose.yml File Step 3: Start the Containers Step 4: Access the WordPress Files Step 5: Managing Containers Step 6: Adding phpMyAdmin (Optional) Step 7: Customizing PHP and Apache Settings

  3. Key Takeaways

  4. Case Studies

  5. FAQs

  6. Conclusion

  7. References

Introduction

Docker is a powerful tool for WordPress development, allowing you to set up isolated environments quickly. With Docker, you can create a local WordPress environment that mimics production, making development and testing easier. In this guide, we’ll cover how to use Docker for WordPress development.

Why Use Docker for WordPress Development?

  • Consistent Environments: No more “it works on my machine” issues.
  • Fast Setup: Get a full WordPress environment running in minutes.
  • Easy Cleanup: Remove and recreate environments without affecting your system.
  • Portability: Move your WordPress setup across different machines effortlessly.

Step 1: Install Docker

Before you start, install Docker Desktop for your operating system. Ensure it’s running before proceeding.

Step 2: Create a docker-compose.yml File

Docker Compose simplifies running multi-container Docker applications. Create a project folder and inside it, create a docker-compose.yml file with the following content:

version: '3.8'
services:
  wordpress:
    image: wordpress:latest
    container_name: wordpress
    restart: always
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: example
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - ./wp-content:/var/www/html/wp-content

  db:
    image: mysql:5.7
    container_name: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: wordpress
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:

This setup:

  • Creates a WordPress container running on port 8080.
  • Creates a MySQL database container with a persistent volume.
  • Maps ./wp-content to /var/www/html/wp-content so themes and plugins persist.

Step 3: Start the Containers

Navigate to the folder containing docker-compose.yml and run:

docker-compose up -d

The -d flag runs it in detached mode (background).

Wait a few seconds, then open http://localhost:8080 in your browser. You should see the WordPress installation page.

Step 4: Access the WordPress Files

Your WordPress files (themes, plugins, uploads) are in the wp-content folder. You can edit them locally, and changes will reflect in the running container.

tep 5: Managing Containers

  • Stop containers:
docker-compose down
  • Restart containers:
docker-compose restart

View running containers:

docker ps

Step 6: Adding phpMyAdmin (Optional)

To manage your database visually, add the following service to docker-compose.yml:

phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - "8081:80"
    environment:
      PMA_HOST: db

Now, access phpMyAdmin at http://localhost:8081.

Step 7: Customizing PHP and Apache Settings

If you need custom PHP settings, create a php.ini file inside your project:

upload_max_filesize = 64M
post_max_size = 64M

Then, modify the docker-compose.yml to mount this file:

volumes:
  - ./php.ini:/usr/local/etc/php/conf.d/custom.ini

Case Studies

Case Study 1: Development Team at XYZ Agency

XYZ Agency struggled with inconsistent development environments. By adopting Docker for WordPress, they reduced onboarding time for new developers from two days to two hours and eliminated environment-related issues.

Case Study 2: Freelance Developer’s Efficiency Boost

A freelance developer used to spend hours setting up local WordPress instances. After switching to Docker, they cut setup time by 75%, allowing them to take on more projects.

“Docker saves me so much time! I can spin up a full WordPress site in minutes and start coding right away.” — Jane Doe, WordPress Freelancer

Key Takeaways

  1. Docker provides a fast and reproducible way to set up a WordPress development environment.
  2. docker-compose.yml makes it easy to define and manage multiple containers.
  3. Mapping wp-content ensures theme and plugin development persists across container restarts.
  4. phpMyAdmin can be added for database management.
  5. Custom PHP settings can be applied using a php.ini file.

FAQs

1. Can I use a different database instead of MySQL?

Yes, you can replace MySQL with MariaDB by updating the db service in docker-compose.yml:

image: mariadb:latest

2. How do I remove all Docker containers and images?

To clean up your system, use:

docker system prune -a

3. Can I use Docker for WordPress in production?

Yes, but you should optimize security, enable SSL, and configure persistent storage.

Conclusion

Docker provides a flexible and efficient way to set up a WordPress development environment. With docker-compose, you can quickly deploy and manage WordPress along with MySQL and other necessary services.

By following this guide, you’ll have a fully functional, portable WordPress setup ready for development. 🚀

References

  1. Docker Desktop (Official Download)
  2. Docker WordPress Image (Official Docs)
  3. Docker Compose Documentation
  4. MySQL Docker Image (Official Docs)
  5. phpMyAdmin Docker Image
  6. Docker Logs & Debugging Guide
  7. Docker System Prune (Cleanup Command)

메타데이터
post_id
6eb114a42b5f
slug
how-to-use-docker-for-wordpress-development-6eb114a42b5f
url
https://medium.com/addweb-engineering/how-to-use-docker-for-wordpress-development-6eb114a42b5f
canonical_url
https://medium.com/addweb-engineering/how-to-use-docker-for-wordpress-development-6eb114a42b5f
author_url
https://medium.com/@pratik_addweb
status
ok
fetched_at
2026-08-12 08:09:52