How to Install WordPress on Docker (Windows, macOS and Linux)
access_time
hourglass_empty
person_outline

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.

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:

  1. Update the package list:
    sudo apt-get update
  2. Let apt access a repository over HTTPS:
    sudo apt-get install 
        apt-transport-https 
        ca-certificates 
        curl 
        gnupg-agent 
        software-properties-common
  3. Add the Docker’s GPG key:
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. Add the Docker’s repository:
    sudo add-apt-repository 
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu 
       $(lsb_release -cs) 
       stable"
  5. Update the Docker’s repository:
    sudo apt-get update
  6. 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:

  1. Download Docker for Mac and double-click the .dmg file you’ve saved. Then, drag and drop the Docker icon to your Applications folder. Docker for Mac
  2. Open your Applications folder and double-click docker.app. During the configuration process, you’ll be asked to enter your password.
    Enter Password for Docker on macOS
  3. 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:

  1. Enable Hyper-V in your system.
  2. Download Docker Desktop for Windows and open the Docker for Windows Installer file.
  3. In the Configuration dialog window, check or uncheck the boxes based on your preferences. Click Ok.This image shows you the configuration options when installing Docker on Windows
  4. 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:

  1. Check Docker Compose Installation:
    docker-compose --version
  2. Create a new directory for WordPress:
    mkdir ~/wordpress/
    cd ~/wordpress/
  3. 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: {}
  4. Run this command in the directory to create the containers:
    docker-compose up -d
  5. Your browser will enter localhost:8000 and display the WordPress setup screen.Docker WordPress Installation 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.

The Author

Author

Domantas G. / @domantas

Domantas leads the content and SEO teams forward with fresh ideas and out of the box approaches. Armed with extensive SEO and marketing knowledge, he aims to spread the word of Hostinger to every corner of the world. During his free time, Domantas likes to hone his web development skills and travel to exotic places.

Related tutorials

Author

Frederick Reply

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.

Author

Kenji Reply

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

    Author

    Domantas G.

    Replied on September 24, 2019

    Hey Kenji, Thanks for your input!

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

Become a part of Hostinger now!

More in WordPress
How to Fix WordPress Login Redirect Loop Issue
How to Fix WordPress Login Redirect Loop Issue

Close