November 7, 2019
3min Read
Domantas G.
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.
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.
Follow the steps below and learn how to install WordPress on Docker.
Docker is available for Windows, macOS, and Linux. Here’s how you can install it on those three operating systems:
If you’re using Ubuntu 18.04 LTS, follow these steps:
sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
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.
Here are the procedures to install Docker on macOS:
Here’s how you can install Docker on Windows 10 64-bit:
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:
docker-compose --version
mkdir ~/wordpress/ cd ~/wordpress/
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: {}
docker-compose up -d
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.
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
November 22 2019
just followed this tutorial on my Mac (10.15) and I cannot believe how simple this is. It just works! Great!!
Domantas G.
Replied on September 24 2019
Hey Kenji, Thanks for your input!