How to Install WordPress on Docker (Windows, macOS and Linux)
If you are looking for a way to create isolated environments to test your WordPress, then familiarize yourself with container technology. In this article, we’ll cover a step-by-step guide to install WordPress on Docker, the best-known container platform.
Download Complete Linux Commands Cheat Sheet
What Exactly Is Docker?
Docker is an open-source containerization software that creates isolated environments to run an application. Hence, you develop, test, and run multiple applications on the same machine.
In contrast to virtual machines, each container does not require its own OS and shares the host’s kernel. Thus, the machine’s workload is far more lightweight and a single server can run multiple containers at the same time.
For that reason, Docker is highly useful for WordPress developers. A WordPress test environment usually eats up a lot of system resources, but Docker helps them make a minimal environment without wasting server space and memory.
How to Install WordPress on Docker?
Follow the steps below and learn how to install WordPress on Docker.
Step 1: Installing Docker
Docker is available for Windows, macOS, and Linux. Here’s how you can install it on those three operating systems:
Linux Installation
If you’re using Ubuntu 18.04 LTS, follow these steps:
- Update the package list:
sudo apt-get update
- Let apt access a repository over HTTPS:
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
- Add the Docker’s GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Add the Docker’s repository:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- Update the Docker’s repository:
sudo apt-get update
- Install Docker:
sudo apt install docker-ce
Keep in mind that other Linux distributions (CentOS, Debian, or Fedora) have different installations steps. If you don’t use Ubuntu, see Docker’s official documentation.
macOS X Installation
Here are the procedures to install Docker on macOS:
- Download Docker for Mac and double-click the .dmg file you’ve saved. Then, drag and drop the Docker icon to your Applications folder. You can find download links here:
- Open your Applications folder and double-click docker.app. During the configuration process, you’ll be asked to enter your password.
- Once the installation process is finished, you’ll see the docker menu in your desktop’s status bar.
Windows Installation
Here’s how you can install Docker on Windows 10 64-bit:
- Enable Hyper-V in your system.
- Download Docker Desktop for Windows and open the Docker for Windows Installer file.
- In the Configuration dialog window, check or uncheck the boxes based on your preferences. Click Ok.
- Once the installation is finished, hit Close. You’ll see the Docker icon in the taskbar.
Step 2: Setting-Up WordPress on Docker
Next, let’s set up WordPress on Docker. You can do this process with these two methods ‒ the CLI and Docker compose.
In this article, we’ll be using Docker compose, the cleaner and more systematic method. Here’s how:
- Check Docker Compose Installation:
docker-compose --version
- Create a new directory for WordPress:
mkdir ~/wordpress/ cd ~/wordpress/
- Create a new docker-compose.yml in the new directory and paste the content below. Don’t forget to change the credentials.
version: '3.3' services: db: image: mysql:5.7 volumes: - db_data:/var/lib/mysql restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress WORDPRESS_DB_NAME: wordpress volumes: db_data: {}
- Run this command in the directory to create the containers:
docker-compose up -d
- Your browser will enter localhost:8000 and display the WordPress setup screen.
Conclusion
Docker is a great containerization tool to experiment with WordPress. Its minimal environment helps you maintain the efficiency of your system resources.
In this tutorial, you’ve learned how to install Docker on Linux, macOS, and Windows. You’ve also learned how to set up WordPress on Docker using the Docker Compose utility.
We hope this simple tutorial is helpful. If have any further questions, share with us in the comments section below.
Comments
June 29 2017
Great tutorial. Thanks for putting this out there. Once someone is finished developing their wordpress based site, do you provide the container to a host or export the wordpress and associated database in the traditional sense? Maybe I'm picturing this inaccurately, but I'm assuming you shove the docker container into a slot on some docker compliant host and it just runs from there. Any guidance appreciated! Thanks.
September 10 2019
Great tutorial. Really helped me getting my first babysteps towards Docker. Two things that aren't mentioned and took some time for me to figure out, since newer versions are out. I got an error when I tried to run "docker-compose up -d" >> ERROR: client version 1.22 is too old. Minimum supported API version is 1.24, please upgrade your client to a newer version This one is very simple to solve: Open the yml file and change the version from 2 to 2.1 >> Pulling from library/php no matching manifest for windows/amd64 in the manifest list entries Also very simple to solve: 1 Right click Docker instance 2 Go to Settings 3 Daemon 4 Advanced 5 Set the "experimental": true 6 Restart Docker
September 24 2019
Hey Kenji, Thanks for your input!
November 22 2019
just followed this tutorial on my Mac (10.15) and I cannot believe how simple this is. It just works! Great!!
April 24 2021
Hey, Domantas G. Thanks to you I am able to set up WordPress using docker. thanks a lot
September 14 2021
If you're running this on Linux you have use "sudo docker-compose up-d" or you will receive an error message about http+docker://localhost not runnning.
December 19 2021
Excellent tutorial, I was stuck at a place as I was working with docker for one of my clients, and this article completely helped me in satisfying the cleint. Thank you so much Domantas, Kudos!
December 22 2021
Happy it worked out!
January 02 2022
Thanks, this worked amazingly well, and quickly! One thing though, I don't know where the active `wp_content` folder is. How do I develop themes and plugins in this?
January 04 2022
Hi Mike, generally your wp-content will be right next to wp-admin and wp-includes folder. You can use
find
command on Linux or Mac to find the location of your folder! Here's how to use the find command :)March 26 2022
pleace i have "Error establishing a database connection"
March 29 2022
Hi there! It looks like you might have a problem with either of these things: (1) you haven't created a database yet; (2) your database credentials on your wp-config.php file are incorrect; (3) you're reaching the memory limit of your server. I'd suggest to start by checking them :)
March 30 2022
thanks