A short introduction to Docker and WordPress including the underlying necessary services and how it will interact with each other.
Table of Contents:
1. What is Docker?
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.
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.
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.
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.