jpvalery
By:
jpvalery

What would be the advantages on running dockerized WordPress ?

January 31, 2015 7k views

Hi everyone,

After years of shared hosting, I'm ready to take the leap and move on to the next step :)
Even though I've some basics in Linux, I guess that this is going to be an exciting challenge.

I'm still cramming the excellent tutorials of the community, especially the ones about LEMP and securing the VPS.

However, I see all the hype going around docker and read on a few places about running WP and MySQL in dockerized containers. And I was just wondering what the advantages would be ?
Or if a LEMP stack alone would be enough ?

So, if some people have some wisdom to share, I'd be glad to learn from your experiences :)

Thanks in advance !

Cheers,

5 Answers

There are a number of advantages to using Docker over configuring a server yourself. For one, there's convenience. Know how many steps it takes to setup a new Wordpress blog using docker? Two!

docker run --name mysql -e MYSQL_ROOT_PASSWORD=some-secret-string -d mariadb
docker run --name myblog --link some-mysql:mysql -p 80:80 -d wordpress

Of course, that's for a pretty simple setup. This will bind the port 80 of your host system to the docker instance running Wordpress, so you can't host anything else on the same server. But if you want, you can run any number of docker containers on a single server by setting up a reverse proxy like nginx or haproxy.

Secondly, you will gain access to the vast library of ready-to-deploy application images at the Docker registry (https://registry.hub.docker.com). The Wordpress and MariaDB images used above are examples of this. Pretty much any web application that has attracted notice now has Docker images ready for you to use.

The third is, in my opinion, neatness. Your server itself will not have a big stack installed, like LAMP: all your server needs to know is how to run docker containers. After that, you can run any number of services in containers, and they are completely separate. Want to run rails? Add a container. Django? Add a container. If you want to run three apps on different versions of Ruby, normally you'd have to do some pretty messy stuff with rbenv or rvm. Now, you can simply package your app in different containers, and you host won't care!

And finally security: if you deploy an app with a vulnerability and hackers gain root, they will only have root inside a single docker container, and can't get at your host system.

I've been looking into Docker myself recently, and was surprised at how powerful it can be. I've taken Wordpress blogs offline and brought new ones up in seconds, using only a single Droplet. I've written about my experiences: http://blog.romkevandermeulen.nl/2015/01/31/dokku-docker-server-power-control/

I hope that helps you out. I'm happy to discuss it further if you have any more questions. Let me know!

Hey !

Waoh thanks for that extensive answer !

To give you more insights : I'll be transferring a huge WP to DO in the coming weeks. And that'll be the only thing on that droplet.

As much as the security part is really convincing me, I'm afraid it'll end up being more complicated for me than a classic LEMP stack considering that I'll be transferring a pretty big website.

What's your opinion on this ?

Transferring an existing WP can be a lot of work, and learning Docker on top of that can make it even more difficult. If you're used to shared hosting and not very familiar yet with setting up and using a LEMP stack, it might be advisable to start with a Wordpress droplet. You can move on to Docker once you're more confident.

I do advice you to start learning Docker at some point: the way things are looking now, the future of hosting seems to be in application containers, and Docker is leading the field. You could start out with playing with it on your local computer. There's any number of tutorials you could try. Once you've got the hang of it, you can fire up a new Docker droplet and see if you get your WP working on that without transferring the domain name until you're sure you're ready.

Thanks for your reactivity buddy.

Well, the issue is that the WP droplet is set up with a LAMP where I'd like to try out a LEMP ^^'

Wouldn't be the move to Docker be more complicated later than now ?
I mean, we're not in a hurry, and I'd prefer to set up something evolutive and reliable.
Even if that means spending long hours cursing my past self over taking that decision, because it'll be worth it on the long run :D

Thanks again for sharing your wisdom !

Well, if you're willing: once you've gotten the basics of Docker down, it's not much harder to set up your stuff in a Docker container than directly on your host. In essence, a container is an isolated miniature OS.

Why don't you try installing Docker on your own computer and running these two commands:

docker run --name mysql -e MYSQL_ROOT_PASSWORD=some-secret-string -d mariadb
docker run --name myblog --link some-mysql:mysql -p 8080:80 -d wordpress

Then go to http://localhost:8080 and you should see a new Wordpress blog.

To run a shell inside a running container, you'd run this:

docker exec -it myblog bash

That'll launch the command bash inside the myblog container. Once you're inside the container, you can look around to see how things have been set up. After all, the best way to learn is by example.

Here's the Dockerfile for the official wordpress Docker image. You can study that to see how the Wordpress container was constructed.

When you understand how things are set up inside you container, you can worry about how to expose that container to the world. If you only want to host one Wordpress blog on your server, the easiest solution would be to directly bind port 80 from the host to the Wordpress container. If you want to host multiple applications from one server, you need something like docker-gen to assign domain names to specific containers.

  • One note: the official Wordpress image uses Apache. I'm sure there's plenty of people who've contributed a Wordpress-LEMP image you could use. Or you could start from a base image like ubuntu and set everything up yourself. Honestly though, I wouldn't worry too much about which server is running inside the container itself unless you have specific concerns with Apache: the beauty in containers is that you point traffic at their port 80 and it just works.

    If you do want to try setting up a Wordpress-LEMP stack, I've written some nginx config files that can help you get started, including for Wordpress.

Have another answer? Share your knowledge.