I have been playing about with Docker Desktop for Mac over the past few days and I am astounded with just how straightforward and easy it is to have applications up and running within just a few minutes. I think about all the time I spent learning the intricacies of installing software like Wordpress and Nextcloud in full VM's and LXC containers…and then I think that this whole process could have been simplified by moving to Docker. Nextcloud in particular was an absolute pain to get installed, and upgrading it always leaves me a bit nervous waiting for things to break.
To get a basic installation of Wordpress and MySQL working in Docker is very straightforward. Infact, it seems to be the work of just two commands!
Step One - Install MySQL
Wordpress depends on a database to work. Installing MySQL manually and adding a database and users to it is really intimidating to new users (and certainly frustrating when I first did it). Remove all of this complexity with the following command;
$ docker run --detach --name=mysql_wordpress --env="MYSQL_ROOT_PASSWORD=*Replace with password*" mysql:*Version*
--detachoption means that the container starts and drops to a background process. You can see if it is running by running
$ docker ps
--name=option is to name the container. In this case it will just be used for this Wordpress install.
--env=option passes variables through to containers. In this case, it is setting the root password for the MySQL database. MAKE SURE THIS IS SUPER SECURE AND YOU WON'T LOSE IT! (I recommend a password manager - see this post.)
mysql:option is the actual container we want to download and run. In this case it's the official MySQL image hosted on Docker Hub here.. The
*Version*option is which version of MySQL you want to run. The entry on Docker Hub gives more detail on which versions are available. If you want the latest version, you would type
Step Two - Install Wordpress and Link it to MySQL
With MySQL installed and running, all you need to do now is grab a Wordpress image and link it to the MySQL container. We will be using the official Wordpress image on Docker Hub found here. The following command needs to be run to get running;
$ docker run --detach --name *Your Website* --link mysql_wordpress:mysql -p 8080:80 wordpress
--nameoption works the same as MySQL above, replace with the name of your website.
--linkoption links the container to the MySQL container so they can always see each other. This is important as Docker gives a new ip address to a container every time it is run. If containers are linked together, it does not matter what ip they are given as they can always share data with each other.
-p 8080:80option is important as it maps port 8080 of the machine docker is being run on to port 80 of the wordpress container. If this is not done no connections from outside of the container can reach it…and no webpage will be delivered!
wordpressoption is just the name of the official Wordpress container on Docker Hub.
You're basically done! Head to
localhost:8080 on the machine that you're running Docker on and you should find yourself presented with a Wordpress installation setup wizard. Careful here to ensure that you note the login information you supply - password managers are your friend!
That's it! In some ways it's almost frustrating how easy Docker makes getting quite difficult software infrastructure running in just a couple of commands if you have spent time learning the traditional way. I don't think I want to go all-in on Docker at the moment as my setup with LXC containers works just fine for me, but running a Docker host in the future is definitely something I will consider doing. The really fun part is how integrated Docker is with Kubernetes, another new and exciting technology designed to allow you to auto-scale your containers into a cloud. I haven't really tried Kubernetes…but perhaps in the future.