Containerisation with Docker Part Two

Having successfully got WordPress and MariaDB running in Docker containers and talking to each other so they could host this very website my attention turned to what else I could run in a Docker container that might be useful.

My son is, like most children his age, interested in Minecraft. Minecraft can be played on a variety of different platforms from mobiles to laptops to games consoles. Generally these games are played in isolation or via a direct invitation between two or more players but there is another option which is to have a server that one or more players can connect to. That doesn’t rely on any one player having to host a game.

Interestingly there are several pre-built Docker containers for Minecraft servers. The most popular seems to be Note that I’ve chosen one that mentions “bedrock”. There are two types of server one for Java edition which can only be used from the Java version of Minecraft which runs on PC and the other is used by the console, Windows 10 and mobile editions and that is the one known as Bedrock edition.

As I had done previously I created a folder on the host VPS server that would hold the data for the Minecraft container so that we could control settings on it and enable it to persist across container restarts. I mapped this folder to the container using the settings in the Plesk control panel and then set an environment variable called EULA and set the value to True which is required to make a Minecraft server start successfully. I also configured the appropriate port and allowed it through the Plesk and IONOS firewalls.

I started up the container and watched the logs report a successful startup. Then it was time to try and connect to it. This was surprisingly difficult because Microsoft don’t allow users to specify servers on Xbox One edition. However as is often the case someone ingenious on the internet had provided a workaround and we were soon able to find a way to connect to our server and my son was able to start doing some work on the world generated on the server.

The next task was to prevent the entire internet from connecting to the server. There is an in-built way of doing this by using a file named whitelist.json which contains a list of known Minecraft users who can access the server but this relies on all users having Microsoft / Mojang accounts which not all of my son’s friends had. This meant we had to go slightly old school and use a firewall restriction in the Plesk control panel so after teaching some 12 year olds how to use What’s my IP we had a list that we could use to restrict access to only those that were permitted to connect.

Containerisation with Docker – Part One

Running applications and services in their own containers has become popular recently. Containers have several advantages over virtual machines including the lack of requirement of another licence and no need to dedicate resources to the virtual machine.

Docker is a tool that allows us to create containers.

I recently obtained a VPS server from IONOS to use to do a little bit of research on various topics and decided that Docker would be a good starting point. The VPS server administration panel included Plesk and I was able to install Docker using Plesk.

Using the GUI in Plesk I created containers for MariaDB and WordPress because my first intention was to create a WordPress website that I could use to host a blog (wonder how that turned out?!).

Whilst the GUI allowed me to do a certain amount of configuration of the containers for each of the applications it soon became apparent that I would need to use the command line to really get the most out of Docker.

As an aside it’s interesting how much more prevalent the use of command line tools is these days, when I started working in IT command line tools were already practically out of fashion but they are back with a vengeance these days. I guess Powershell might have kickstarted that in the Microsoft stack and obviously working with Linux or Unix based systems has always been easier with the command line.

The first thing that I needed to do was to create folders on the host machine that could be mapped across into the containers to provide persistent storage. A container effectively starts from scratch each time it is started so for anything to persist it needs to be stored on the host machine and the location of that storage needs to be mapped into the container. Using an SSH connection to the VPS I created directories that could be used to hold data for the MariaDB and WordPress containers.

I could then use the environment variables configuration in Plesk to map these new directories so that they were available to the Docker containers. Starting the containers everything seemed to be good but WordPress needs to know where the database it can use is as it starts up and currently I had two containers and needed to get them to talk to each other.

The way to establish connection between the two containers was to create a network and then add the two containers into that network using the following three commands:

docker network create [networkname]
docker network connect [networkname] [dbcontainername]
docker network connect [networkname] [wordpresscontainername]

Now both containers can talk to each other using the logical names attributed to them in the environment variables.

All that was left was to configure a rule in Plesk to forward requests to the domain name through to the WordPress Docker container and to then start both containers. When I accessed the domain name I was then able to complete the WordPress installation.

The final test was to stop both containers and check that when they restarted the installation was still all set up – I tested it and it was so my first Docker containers were up and running.