Benefits of Managing Docker Containers with Orchestration Software

You are viewing an old version of this article. View the current version here.

In this page we'll discuss why automating Docker containers with software like Ansible or Puppet may be desirable. To talk about this, we'll first need to discuss why Docker containers are defined ephemeral, and how this applies to containerized database servers, and why we

Docker's Ephemeral Nature

Docker images are compiled from Dockerfiles. Containers are created from images. Normally, a container is not modified since the moment it is created. In other words, containers are usually designed to be ephemeral, meaning that they can be destroyed and replaced with new containers at any time. Provided that there is proper redundancy (for example, there are several web servers running the same services) destroying one container and starting a new one of the same type won't cause a damage.

We will discuss a bit later how this applies to MariaDB, and more generally to database servers.

When something should change, for example some software version or configuration, normally Dockerfiles are updated and containers are recreated from the latest image versions. For this reason, containers shouldn't contain anything that shouldn't be lost, and recreating them should be an extremely cheap operation. Docker Compose or the Swarm mode are used to declare which containers form a certain environment, and how they communicate with each other.

On the contrary Ansible is mainly built to manage the configuration of existing servers. Docker and Ansible have very different approaches. For this reason, Ansible is not commonly used to deploy containers to production. However, using them together can bring some benefits, especially for development environments.

More on this later in the page. First, we need to understand how these concepts apply to database servers.

Stateful Technologies

Using ephemeral containers works very well for stateless technologies, like web servers and proxies. These technologies virtually only need binaries, configuration and small amounts of data (web pages). If some data need to be restored after a container creation, it will be a fast operation.

In the case of a database, the problem is that data can be large and need to be written somewhere. We don't want all databases to disappear when we destroy a container. Even if we had an up to date backup, restoring it would take time.

However, Docker has features called volumes and volume containers. We won't discuss the difference here, let's focus on their purpose. A volume is a directory in the host system mapped to a directory in one or more containers. Volumes are not destroyed when containers are destroyed. They can be used to shared data between any number of containers and the host system. Therefore, they are also a good way to persist data.

Suppose a MariaDB container called mariadb-main-01 uses a volume that is mapped to /var/docker/volumes/mariadb-main. At some point we want to use a more recent MariaDB version. As explained earlier, the Docker way to do this is to destroy the container and create a new one that uses a more recent version of the MariaDB image.

So, we will destroy mariadb-main-01. The volume is still there. Then we create a new container with the same name, but based on a newer image. We make sure to link the volume to the new container too, so it will be able to use /var/docker/volumes/mariadb-main again. At this point we may want to run mysql_upgrade, but apart from that, everything should just work.

The above described steps are simple, but running them manually is time consuming and error-prone. Automating them with some automation software like Ansible or Puppet is often desirable.

Benefits of Managing Docker Containers with Automation Software

Docker containers can be entirely managed with Docker Compose or the Swarm mode. This is often a good idea.

However, choosing to use automation software like Ansible or Puppet has some benefits too. Benefits include:

  • Docker containers allow to work without modifying the host system, and their creation is very fast. Much faster than virtual machines.
  • As explained, making all containers ephemeral and use volumes to store important data is possible. But this means adding some complexity to adapt an ephemeral philosophy to technologies that are not ephemeral by nature. Also, many database professionals don't like this approach. Using automation software allows to easily trigger upgrades and configuration changes in the containers, treating them as non-ephemeral systems.
  • Sometimes Docker is only used in development environments. If production databases are managed via Ansible, this could lead to some code duplication. Dealing with configuration changes using the same procedures will reduce the cost of maintenance.
  • While recreating containers is fast, being able to apply small changes with Ansible can be more convenient.
  • Trying to do something non-standard with Dockerfiles can be tricky. For example, running two processes in a container can be problematic. However there are situations when this is desirable, for example PMM containers run several different processes. Launching additional processes with Ansible can make things easier.

Content initially contributed by Vettabase Ltd.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.