WordPress Docker

Tweet about this on Twitter0Share on Facebook21Share on Google+0Share on LinkedIn1

You probably already heard about Docker and LXC containers. Also I wrote a post about LXC and how easy you can use it for testing here. So in this post I will not rewrite something that you already read on Docker website.

Even if it isn’t quite ready for production you can use Docker for continuous integration and development. I wrote a simple WordPress Docker images, actually image representations called Dockerfiles which you can run on your Docker host: https://github.com/komljen/dockerfile-examples

There is a couple of those out there, but most of them are using just one container with bunch of processes in it. I think that idea about Docker is one processes per container. Why? Simply because there isn’t any overhead of running ten containers or ten processes in one container. You should really use layers and all good things of copy on write technology. From the other side it is easier to manage small pieces than one large container.

To run this WordPress container you will need git, docker (0.6.6 >) and shyaml shell yaml parser. If you are running Ubuntu 12.04.3 LTS which comes with 3.8 kernel docker installation is quite simple:

Then check your Docker version:

Install shyaml parser:

When all is ready clone git repository:

And run two simple commands to get everything up and running. First one with build argument will build images. Build part will take some time because it builds images without cache, but second time it will just rebuild WordPress image or last layer in this infrastructure. That means each time you run bellow command it will download latest WordPress from their official web site:

After it finishes list docker images:

You should see this output:

As you can see all images are created. Big picture of layers and images:

flow

Now it is a time to run WordPress:

You should see this output:

And your WordPress is ready, just point your web browser to: http://your_host_ip
Inside WordPress container a lot of things will happen. It will create new database, move all files to apache root directory, change wp-config.php and finally start apache web server.

One interesting fact about this WordPress container is that apache root directory (/var/www) is added to Docker volume. From that perspective you can access to all files inside that directory from new container, so you don’t need sshd daemon to go inside running container to change something. This is how that works:

Now you are in new container. So you want to remove or edit .php file? No problem:

Do something and refresh your browser. Or you want to access to your database:

Seems like magic. When you are finished just close your connection and newly created container is stopped. All WordPress related things are in WordPress image and you can simply reuse ubuntu, apache and mysql images for anything else. To restart to fresh WordPress installation:

Above script can be used to clean all untagged images or clean stopped containers:

Happy dockerizing until next part. For any questions feel free to post a comment.

Tweet about this on Twitter0Share on Facebook21Share on Google+0Share on LinkedIn1
Posted in Deployment and tagged , , .

Alen Komljen

I'm a DevOps/Cloud engineer with experience that spans a broad portfolio of skills, including cloud computing, software deployment, process automation, shell scripting and configuration management, as well as Agile development and Scrum. This allowed me to excel in solving challenges in cloud computing, and the entire IT infrastructure along with my deep interest in OpenStack, Ceph, Docker and the open-source community.