Setting Up a Local WP Development Environment with Docker

Introduction

Are you a web designer looking to streamline your local development process? Docker is a powerful tool that can help you easily manage your development environments. In this guide, I’ll walk you through the steps to set up a local WordPress development environment using Docker on Ubuntu.

Prerequisites

Before we begin, ensure you have the following:

  • Docker installed on your system. If you haven’t installed Docker yet, you can find the installation instructions in our article: How to Install Docker on Ubuntu.

Step 1: Create a Docker Network

First, we need to create a network for our containers to communicate. Open your terminal and run the following command:

This command sets up a virtual network named wp_network. It allows our WordPress and MySQL containers to communicate seamlessly.

Step 2: Run the MySQL Container

Next, let’s set up the MySQL database. Run the following command in your terminal:

  1. Explanation of the command:
    • --name mysql-container: Names the container for easy reference.
    • --network wp_network: Connects the container to the network we created.
    • -e MYSQL_ROOT_PASSWORD='useYOURpa55wordHERE!': Sets the root password for MySQL.
    • -e MYSQL_DATABASE=wordpress: Creates a database named wordpress.
    • -v mysql_data:/var/lib/mysql: Persists data using a volume named mysql_data.
    • -d mysql:8.0: Runs the container in detached mode using the MySQL 8.0 image.

Step 3: Run the WordPress Container

Now, we’ll set up the WordPress container. Run this command:

  1. Explanation of the command:
    • --name wordpress-container: Names the WordPress container.
    • --network wp_network: Connects to the same network as the MySQL container.
    • -p 8080:80: Maps port 8080 on your host to port 80 on the container.
    • -e WORDPRESS_DB_HOST=mysql-container:3306: Specifies the MySQL host and port.
    • -e WORDPRESS_DB_USER=root: Sets the database user.
    • -e WORDPRESS_DB_PASSWORD='useYOURpa55wordHERE!': Uses the same password we set for MySQL.
    • -d wordpress: Runs the WordPress container in detached mode.

Step 4: Accessing WordPress

Congratulations! Your WordPress site is now running. Open a web browser and go to:

You should see the WordPress setup page. Follow the prompts to complete the installation.

Step 5: Managing Containers

To manage your containers, you can stop and start them as needed. Here are the commands:

To stop the containers:

To start the containers again:

This allows you to easily manage your development environment and keep your data safe.

Conclusion

You’ve successfully set up a local WordPress development environment using Docker! This setup allows you to work on multiple WordPress sites efficiently. Feel free to experiment and customize your WordPress setup as needed.

If you have any questions or feedback, please let me know in the comments below. Happy coding!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.