If you’ve been paying attention to the recent rumblings in the web/app development space, there’s a good chance you’ve encountered the term ‘containers.’ And for good reason. Containerization has multiple use-cases: whether you’re looking for an isolated environment to test your application, or want to make your application portable for easy deployment on any machine.
One of the most famous containerization solutions is Docker. It is so popular, that in fact, it is difficult not to bring up Docker when discussing containers.
In this tutorial, we will show you how to utilize Docker for your WordPress projects. This guide will prove to be beneficial for those who want a sound yet minimal environment to run isolated tests on their projects. It will also be useful for serving as a playground for experimentation with various WordPress plugins and themes.
So, sit back and behold the wonders of containerization.
How to Install WordPress on Windows 10 Computers with XAMPP Support Step 1: Download XAMPP Package. Step 2: Install XAMPP. After downloading the Windows version, you should be prompted install. Step 3: Configure XAMPP. Now that the package is installed, open XAMPP and start up Apache.
Before starting this tutorial you’ll need:
Containers could easily be understood through the concept of virtual machines. Similar to virtual machines, containers provide security by running separate instances of operating systems simultaneously with no interaction with each other. Also, like virtual machines, containers enhance the portability and flexibility of your projects, as you are not dependent on any specific hardware, and can migrate over to any other cloud, local environment etc.
But in contrast to virtual machines, which require an installation of fully-featured operating systems along with their often-bulky overhead, containers share the kernel of a single operating system while still maintaining isolation with respect to other containers. In short, you get the same benefits of virtual machines, without the overhead costs.
Docker uses the same scheme to create containers on a Linux-based VM. In a single Docker container, you get access to all of your development needs: source code, dependencies, and runtimes.
This is especially useful for WordPress developers. Not only is it a chore to setup a test environment for WordPress (database, dependencies, server), but you also end up throwing away valuable system resources like server space, memory etc. Docker can vastly improve this, by setting up a minimal environment, that you can take anywhere with you.
Fortunately, Docker is available on all the major operating systems: Windows, macOS, and Linux. Less fortunately, the level of Docker support fluctuates between these operating systems. So, depending on which operating system you’re using, your mileage may vary.
Linux is the recommended operating system when it comes to Docker deployment. This is due to the fact that Docker was originally released on Linux back in 2013. Docker installation on different Linux distributions will be different. Steps below show how to install Docker on Ubuntu 14.04 LTS, if you are running different Linux distribution, see official Docker documentation.
Since the Yosemite update, macOS also supports Docker. Though not as robust as the Linux version, you can still mostly achieve the same on your Mac machine with Docker:
Due to sufficient market demand, Docker was ported to mainstream Windows versions in June 2016. Before this, only Windows Server users were able to use Docker on Microsoft’s platform. Now, you only need to have a 64-bit version of Windows 10. In addition to the OS requirement, you also need to enable Hyper-V, which you can yourself by booting into your BIOS or let Docker’s Installer do it for you.
Speaking of which, download and run the Docker Installer for Windows. We recommend going with the Stable release, though you are welcome to choose the Edge or Legacy Edge versions. During the installation phase, you will be asked for your system password, which is necessary to grant Docker certain privileges.
Once the installation is complete, Docker will launch automatically. You should be able to see the Docker’s Welcome screen at this point. You can verify your installation by opening the Windows command shell (cmd.exe) and running the following commands:
If these are able to run successfully, you are good to go.
Now that you know that Docker has installed properly, you might want to test if it works just as intended. There are a few ways you can do this. The easiest and most common method of testing Docker is to execute”
This command pulls a‘Hello World’ sample image from Docker Hub (more on this later) and creates a new container using that image. As a result of executing the command, you should see the message:
At this point, you are done with Docker’s installation. If you wish to play further with what you can do, read Docker’s official Getting Started page.
Now that you have a working distribution of Docker running on your operating system, we can proceed with deploying WordPress to gain the benefits of containers. Note that from this point onwards, it does not matter which operating system you’re using.
There are two methods of setting up WordPress on Docker. The first is the manual method, which uses the CLI to run WordPress. The second is the cleaner, more systematic method of getting WordPress to run on Docker using Docker Compose, therefore it will be used as an example in this Docker WordPress tutorial.
This is the recommended method for creating a WordPress container, or any container, in Docker. It uses Docker’s very own Docker Compose tool. Each container created via Docker Compose uses a config file, making it easier to port.
If you followed the instructions in Step 1 correctly, you should already have Docker Compose. You should probably still run a check:
Next, you need to create a new directory for WordPress:
Just like the previous section. Once inside the directory, open any text editor and create a new file called docker-compose.yml.
Paste the following in the .yml file and save changes:
This will instantiate a MySQL database service, provide credentials to the database, and pull the WordPress image from Docker Hub.
To run the file, execute this command:
Now in your browser enter localhost:8000 or http://127.0.0.1:8000 and it should result in the ‘Famous 5-Minute’ installation screen.
Docker is a great tool if you want to reap the benefits of containerization. It could be particularly useful for WordPress developers, as their work requires constant experimentation with plugins, themes etc.
In this WordPress for Docker tutorial, you have learned how to install Docker on Linux, macOS, and Windows. You also learned how to setup WordPress both manually using the CLI, and through the Docker Compose utility. By following this tutorial, we hope developers shun virtual machines in favor of containers when crafting WordPress applications.