WordPress on Docker: the videos

https://github.com/johanan/Dockerized-Wordpress-the-Correct-way

I have created a three video series on running WordPress in Docker. This is different than my previous posts on Docker and WordPress. The posts I had written before focused mainly on my journey of moving my site to Docker. This means that many pieces were directly tied to my implementation. These videos and code does not have that requirement. The repository can be used to create a WordPress site from scratch and having running in the cloud in just a few minutes.

WordPress on Docker the Correct way

I keep using the qualifier “the Correct way”. I have explained this in other posts, but I will reiterate it here succinctly. There are quite a few WordPress on Docker containers out there already that run everything in the same container. These containers will allow you to get a site quickly, but everything is tightly coupled. The way I have built it is that the entire implementation of the containers does not matter. As long as you have a backup you can create your site from scratch again. This makes it really easy to run a test site in Vagrant for example. MySQL has an update, destroy your entire site and rebuild. I read a great comment on Hacker News a few days ago. This is paraphrased.

Don’t treat your servers like pets. Treat them like cattle.

This means do not get attached and tweak settings. The entire site should be a repeatable build that starts from scratch. This blog is already on it’s sixth or seventh iteration of changes because I can create my blog from a backup in about seven minutes. This opens the freedom to test and tweak as any complete screw up is fixable in just a few minutes.

Full stack WordPress

The site that is built from my repository can terminate SSL with Nginx and cache your requests with Varnish. This means that you get performance right out of the box. This is important because a WordPress site with many plugins running can be quite slow. When you run my WordPress setup you get a four layer application all built in Docker. The layers are reverse proxy, HTTP caching, a PHP application server, and a database server.

In addition to this you will learn about server provisioning with Ansible. Ansible allows you to take a server in any state and move it to the state you want. This means it makes sure you have the users, packages, and files on the server. Ansible lays the groundwork that you build Docker on. Continue reading “WordPress on Docker: the videos”

WordPress Docker containers

This post will cover what each container in our Dockerized WordPress setup does. This should not be viewed as a standalone post as there is a video playlist that covers more. The playlist demonstrates how you can quickly and easily bring up a Dockerized WordPress install.

First we will start with an image that will explain so much with so little.

Shows how each container links to the others

Yes, there are six different containers. This is so that we can keep each container with a single purpose and even a single process in most cases. We can easily replace and upgrade each container this way. I have blogged on this previously and will not iterate everything here. We will look at each container and any interesting things about each. Let’s get started. Continue reading “WordPress Docker containers”

How to link Docker containers together

This is the third post in a series about moving my WordPress blog into the cloud using Docker.

Download the src(github).

Blog Post Series

At this point we have a bunch of docker images, but no docker containers running. We will fix that in this post. We will look at docker-compose and how it orchestrates bringing up all of our docker containers. Then we will look at some administrative tasks in docker. This includes backing up the site and keeping logs.

Bringing up Docker containers with docker-compose

Docker-compose is a tool from Docker that allows us to define how each container will fit in our application. It makes for a single command to get everything up and running. Docker-compose should already be installed on our target machine by Ansible. First thing we will do is look at our docker-compose.yml which configures everything. Continue reading “How to link Docker containers together”

WordPress and Docker the correct way

Download the src(github).

Blog Post Series

We now have a good foundation to build our WordPress site off of. Docker is installed and ready. We will quickly cover why Docker, some best practices, and finally the actual how of our Docker containers. Much like the previous post, this is not designed to be an introduction to Docker. There are literally thousands of intro to Docker articles and by the time I publish this that number will have doubled. Sign up to any tech newsletter and you will easily see five “Intro to Docker” articles every week. If you want an introduction, go to the official Docker site and you there is an interactive tutorial.

I would also like to point out that if you have followed along or forked my Github repo, you will have a Vagrant machine that has Docker on it by running:

$ vagrant up
$ ansible-playbook -i ./.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory ../ansible/docker.yml

You can then run vagrant ssh and have a completely disposable Docker virtual machine.

Why Docker

The most honest answer I can give to this is that I needed to upgrade my Linux server. I was running Ubuntu 12.04 which is three years old and one LTS release behind. The server was working and I did not want to setup a new one. I had been using Ansible, so I knew I was going to use that. In fact in the beginning I was just going to create an Ansible playbook to install my WordPress stack. I, of course, had heard about Docker and wanted to build something with it. After reading about Docker I decided it would be the most extensible option.

We will discover why in this post. Docker allows us to easily rethink and rebuild our stack from the ground up. Want Apache instead of nginx? Swap it. New version of nginx? Swap it. MariaDB instead of MySQL? You get the idea. This would be very difficult to do without provisioning a brand new server. We also will have a test site that we can run locally that is almost *literally* the exact same as production.

The CORRECT way to use Docker

There are some strong opinions on how a Docker container should be built. I am in the “As few processes as needed, ideally one process” camp. Doing this comes with difficulties and I will list out the issues and what we can do about the issues. Continue reading “WordPress and Docker the correct way”