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:
sudo docker network create wp_network
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:
sudo docker run --name mysql-container --network wp_network -e MYSQL_ROOT_PASSWORD='useYOURpa55wordHERE!' -e MYSQL_DATABASE=wordpress -v mysql_data:/var/lib/mysql -d mysql:8.0
- 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 namedwordpress
.-v mysql_data:/var/lib/mysql
: Persists data using a volume namedmysql_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:
sudo docker run --name wordpress-container --network wp_network -p 8080:80 -e WORDPRESS_DB_HOST=mysql-container:3306 -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD='useYOURpa55wordHERE!' -d wordpress
- 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:
http://localhost:8080
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:
sudo docker stop wordpress-container
sudo docker stop mysql-container
To start the containers again:
sudo docker start mysql-container
sudo docker start wordpress-container
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!