Docker is an open source software and is utilized to bundle software into one container. So what are containers? You can imagine them as a very light version of Virtual Machines being really really fast to boot up. There is a lot more about that but for our understanding it will suffice.
My take on explaining it
I don’t think i am qualified enough to give a professional and comprehensive description nor is the goal of this section to give you an overview. All you need to know though, is that you can create a receipt, called Dockerfile, which bundles every software necessary for your service to run. This receipt can be instantiated into an image and that image can then be run as a container. The main selling point is, that they are running directly on the Host’s Kernel and create a virtual isolated environment which makes them boot up faster than virtual machines which run their own virtualized hardware and operating system.
If you shut down a container every data will be lost and by starting a new one the initial state of the image will be restored hence it’s stateless.
This means ..
To persist data you will need to bind (mount) folders from the host directory to the image. This requires that you have a little understanding on how Linux file system works. For me coming from a Windows background i had a hard and steep learning curve at the beginning however it also helped me greatly to understand the system better.
Advantages of Container
The Docker image or the receipt (Dockerfile) can be shared. In software development it is unsurprisingly very important what software version you are using. By shipping a predefined environment every developer will have the same baseline to work with.
We can just use this guide as an example. At a later point in time i will provide you the “receipt” on how to build this website. For example if you would have installed PHP in another way or from another source your configuration / version might look different than mine. With this receipt we have the same baseline to troubleshoot.
The best practice is to bundle one service into one image. These services can then communicate with each other. If you want to update the software of one service you only need to substitute the image with another image.
However the main advantage of containers lies in their light startup and isolation. One container represents one service only as opposed to virtual machines with full blown operating systems and slow start up and this service is always identical if you use the same image. This means, that you can easily scale your services. Docker swarm allows you to start multiple containers in a computer cluster. If one container breaks, start another fresh one. If one node gets too much traffic, load balance it to another one on the cluster. This is also the start of a whole new topic around micro services.
2. What is WordPress ?
WordPress is an open source content management system and has a huge community. There is a great variety of templates as a baseline to structure your site might it be a blog, website or e-commerce shop. You can expand the functionality through plugins making it both easy to use and maintain even without prior knowledge. If your requirements call for it you can also code your own templates and plugins.
3. What is behind WordPress?
To run WordPress you will need a Webserver which can “understand” PHP since this is the language WordPress is building on and a database which stores your data.
3.1. Caddy as a Webserver
Websites are just files on another computer which are processed to look good on your screen. Those files will be served to you upon your request. The webserver is responsible to serve you the correct files. Common webservers are Apache Webserver or NGINX. However Caddy is also a very viable option. It is a lightweight webserver with automated TLS certification and a very easy to understand configuration. Although i did not work with any other webservers yet it was very easy for me to dive into Caddy. It can be downloaded under caddyserver.com/.
3.2. MySQL and MariaDB as database
With WordPress you don’t save every website in a single file. Every content you create, a blog post, website or category tag is saved into a database. WordPress then utilizes PHP to query the database and output the content onto the template hence it is a content management system. WordPress officially supports the open source database management system MySQL. However you can also use MariaDB since it is a fork of MySQL and can be used as a stand in. There is some historical reason for this forking and although the developers of MariaDB try to synchronize with MySQL in the future some features might be different. For more read this blog post at blog.panoply.io.
3.3. PHP-FPM
PHP is a scripting language and is usually a module which the server calls to interpret scripts on the server side to serve the output to the requested Client. Normally that module would sit on the webserver. However in the case of PHP-FPM the modules are implemented on a separate server. The webserver can then forward the PHP request to that separate module. This again brings the advantage of scalability. In our case it is not really necessary but just a nice practice to separate every service. A small advantage is that we can then update every component independently. It would come handy if you have a raspberry cluster and separate the PHP engine to another node. For further readings refer to hostek.com.
4. Important files of our WordPress installation
We finished defining our services . At this point i want to explicitly again draw attention to the statelessness of our containers. This means we have to “save” important data to our host system by mounting directories to the container (Telling the container it has to link a specific folder inside the container to a folder outside of the container. If files are getting saved into the folder inside that container it will automatically save them at the host file system). Important files will be:
database related data
wordpress including the installation, plugins, themes, etc…
caddy webserver configuration
a folder for saving certificates to serve HTTPS
5. The Raspberry Pi
The Raspberry Pi is a powerful small mini Computer . The biggest difference between it and other computers is, it utilizes different processing instructions. Normally that is not a problem but in our case we want to work with Docker. Using the Dockerfile, images are being built with their respective binaries. This means, that images which work on (e.g.) an Intel processor will not work on our Raspberry Pi’s ARM architecture. This can prove problematic in finding the right software version. For example i did not find any ready to use MySQL v7 image which is why i switched to MariaDB.
Pingback: #3 How to backup Wordpress and what to consider - hungsblog