Skip to content
Go back

WordPress Local Development with Docker: A Complete Guide! 100% Easy Guaranteed

How to Run WordPress on Your Local Machine for Development with the Power of Docker

Table of Contents

Open Table of Contents

Why Use Docker for Local WordPress Development?

As a developer, I once faced the challenge of building a WordPress website directly on a VPS. Making edits directly on the server was cumbersome, risky, and time-consuming. This experience drove me to find a better solution: setting up a local development environment. With Docker, I discovered a powerful and streamlined way to achieve this. I could test, tweak, and perfect the site by building locally before deploying it to the VPS.

You can also use Cloudflare Tunnel to expose your local WordPress site to the internet securely. This is especially useful for sharing progress with clients or collaborators without deploying to a live server. For more details, you can check out the documentation: Exposing Your Local Apps to the Internet [SAFELY!] — Cloudflare Tunnel [2024].

How to Set Up WordPress With Docker

Prerequisites

Step to Perform

1. Clone the Repository

git clone https://github.com/arizmuajianisan/docker-wordpress-mysql-phpmyadmin.git
cd docker-wordpress-mysql-phpmyadmin

2. Setup the .env

3. Create a Docker Network to ensure smooth communication between services:

docker network create your-network-name --subnet 10.0.1.0/24

Update your docker-compose.yml file to use the newly created network:

networks:
  default:
    name: your-network-name
    external: true
    driver: bridge

4. Run Docker Compose Start all services:

docker-compose up -d

5. Access Your Services

Stopping the Services

To stop the running containers:

docker-compose down
docker-compose down

Moving from Local Development to Production

⚠WARNING⚠

Before migrating, ensure WordPress is installed and configured on your production server.

Migration Steps

  1. On the Development Site:

    • Install the UpdraftPlus: WP Backup & Migration Plugin.

    • Use UpdraftPlus to create a full backup, including:

      • Database

      • Plugins

      • Themes

      • Uploads

      • Other files

    • Download the backup files.

  2. Transfer to the Production Server:

    • Copy the backup files to your production server using a secure method (e.g., SCP or FTP).
  3. On the Production Site:

    • Install UpdraftPlus.

    • Upload the backup files.

    • Restore the site using the plugin’s interface.

    • Log in with the credentials from your development site.

Managing Password Securely

The repository includes utility scripts for managing MySQL passwords securely.

For Windows Users

To use these scripts:

  1. Double-click the desired .bat file.

  2. The script will:

    • Generate a random password using OpenSSL.

    • Update the .env file with the new password.

    • Display the password in the console.

  3. Press any key to close the window.

For Linux/Mac Users

To use the script:

1. Make it executable (first time only):

chmod +x generate_root_password.sh

2. Run the script:

./generate_root_password.sh

3. The script will:

Conclusion

By using Docker, you can streamline your WordPress development workflow, ensuring efficiency and reducing risks. This approach lets you perfect your website locally before deploying it to production.


Share this post on:

Previous Post
How To Analyze Network Speed Using Iperf3 and Docker
Next Post
Docker: Change Maximum Upload Size on Wordpress