Is Docker Perfect for Databases?

ClusterEngine
Jul 28, 2017 · 4 min read

What about Databases and Docker

Docker provides a portable and distributable safe haven for database instances, using the isolated container structure. It comes with handy support for deploying self sufficient isolated database environments. The Docker framework allows installation and management of MySQL, MariaDB etc. For this, MySQL and MariaDB Server Docker images are available at official repositories or registries of Docker. After downloading the database server images, Docker is used to create containers for these images. Docker CLI supports all types of control and configuration operations needed for these images to run as fully fledged database instances in isolated containers. Since Docker containers are lightweight abstractions of the host machine, Docker allocates dynamic IP addresses to its containers. Since peer connections are needed, like a peer container running a CMS software needs a static address to connect with the peer database container, Docker allows naming of the containers and instead of the changing IPs, these names, like mysql-container, wordpress-container can be used for interconnections. For incoming connections, the container’s port can be mapped into a host machine port.

The Docker containers provide abstracted filesystem images for the database instances to Read and Write. Also databases can access data directories mounted outside the container, provided they are visible inside the container.

Now, what about the downside?

One criticism is about Volume Management in Docker. If file locking is not properly done, chances are there for an instance to write on another’s file, causing data corruption. Only one running container is allowed to access the database data directory and if another database container tries to access an unlocked file in the former, it may cause startup errors for the latter database instance.

Since filesystems and tools of host can be made accessible to containers and vice versa, serious consequences may happen if a resource in an already configured resource path is removed or stopped. There are security concerns also in this kind of cross-access, especially when security configuration is not carefully done. Another one is Container Crash. Since containers are lightweight images and coupled for distributed workflows, a crash can trigger a cascade of crashes and the data might be corrupted in a database due to an abrupt termination of the database processes.

Next is Over Allocation of Resources issue. Since databases are important components of an enterprise system, and Containers are allocated resources in advance, database containers will get the privilege of the upper limit of resources — memory and computing, even though they are not being used unless during a peak load time. This causes wastage of resources. Also Docker network issues were reported, and when the deployment constitutes of a cluster of replicas that need to communicate 24/7 to main data integrity, a network trouble can cause the replicas to go out of sync.

Docker containers in general are made for stateless software applications and hence reset its data cache every few hours. A database that very much needs a stateful environment may not get it from a Docker Container, without proper configuration and allocation of resources. In case of an abrupt shutdown or crash, data corruption may happen due to this lack of persistence. More than it, the price for extra level of isolation Docker provides for creating a stateful environment to databases, is the extra resource allocation needed in terms of cache space and computing.

Another important argument against connecting Docker and databases are the lack of stability and frequent reporting of bugs with the Docker Container deployment. In a production environment, these can cause costly downtimes in terms of money and reputation. But as with any technology that spans from micro to huge enterprise level, these obviously happen, and a smart engineering team and prompt support team can overcome these hurdles using proper knowledge and expertise.

The Conclusion

Docker containers are an effective way of streamlining application development, testing, deployment and distribution. It offers the much needed portability and flexibility in a cross platform, multi infrastructure host space across the world. While it is an intelligent choice for deploying stateless applications, with some extra planning and effort, they can be made suitable for deploying highly efficient and scalable database systems, irrespective of how and where they are hosted such as clusters, master-slave deployments, cloud instances etc. and this is where Docker gets its upper hand over criticism.

Written by

Expert Database Hosting for Professionals

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade