Docker Guide: How to Try WordPress in a Local Environment

3 min read
Modified

“I want to try WordPress, but I don’t want to mess up my OS by installing PHP and MySQL directly…”

Have you ever felt that way? I definitely have. As an engineer, I prefer keeping my environment clean and having the ability to spin up (and tear down) services in seconds. This is where Docker becomes your best friend.

In this guide, I’ll show you how to launch a local WordPress environment at light speed using Docker. Whether you’re a beginner or just looking for a sandbox to test themes, this procedure is for you.

Why Use Docker for WordPress?

While tools like XAMPP or MAMP were popular in the past, Docker is the modern standard for several reasons:

  • Environmental Isolation: Deleting a container leaves your OS completely untouched.
  • Portability: The same command works the same way on any machine with Docker installed.
  • Ease of Switch: You can run multiple instances of WordPress simultaneously just by changing the port numbers.

3-Step Launch Guide

Setting this up is surprisingly simple. We’ll follow these three steps:

  1. Install Docker
  2. Run the commands
  3. Access WordPress via your browser

1. Install Docker

If you haven’t already, download and install Docker Desktop from the official site.

Docker Desktop: The #1 Containerization Tool for Developers | Docker

Docker Desktop is collaborative containerization software for developers. Get started and download Docker Desktop today on Mac, Windows, or Linux.

www.docker.com

2. Running the Commands

Open your terminal (PowerShell, iTerm, etc.) and run these commands in order:

Terminal window
# Create a network so containers can talk to each other
docker network create wp_net
# Start the Database (MySQL) container
docker run --name db --net=wp_net -e MYSQL_ROOT_PASSWORD=test -e MYSQL_USER=test -e MYSQL_PASSWORD=test -e MYSQL_DATABASE=database -d mysql
# Start the WordPress container (Mapped to port 8080)
docker run --name wp -p 8080:80 --net=wp_net -d wordpress

The docker network create part is crucial. It allows the WordPress container to find the database container using the name db.

3. Accessing WordPress in Your Browser

Wait a few seconds after the commands finish, then open your browser and go to:

http://localhost:8080/

If you see the language selection screen, you’ve successfully launched your containers!

Initial screen after launching. The installation starts here.
Initial screen after launching. The installation starts here.

Initial Setup

Follow the on-screen instructions to finalize the installation.

Database Configuration

Enter the values used in the docker run commands earlier:

  • Database Name: database
  • Username: test
  • Password: test
  • Database Host: db (This works because of the Docker Network we created)
Database connection settings. The key is using 'db' as the host.
Database connection settings. The key is using 'db' as the host.

Site Information

Next, create your admin account and site title.

Setting the site title and administrator account.
Setting the site title and administrator account.

Login and Explore

Log in with your new credentials.

The familiar WordPress login screen.
The familiar WordPress login screen.

Once you see the dashboard, you’re all set! You are now free to experiment with plugins, themes, and content without any permanent consequences.

The dashboard screen. Your new playground is ready.
The dashboard screen. Your new playground is ready.

Cleanup (Deleting Containers)

When you’re done playing, it’s good practice to delete the containers to free up resources.

Note: Deleting containers will delete all posts and settings made within that instance. Think of this as a “disposable” test environment.

In Docker Desktop, you can simply click the trash can icon.

Docker Desktop dashboard. You can manage everything from here.
Docker Desktop dashboard. You can manage everything from here.

To do it via the command line:

Terminal window
docker stop wp db
docker rm wp db
docker network rm wp_net

Conclusion

Docker removes the friction of “environment setup,” allowing you to jump straight into the fun part of web development.

It’s the perfect method if you’re hesitant to try things on a live site or if you’re just curious about WordPress. If you want to take it to the next level, I suggest looking into docker-compose next—it will make managing these multi-container setups even easier!