When to Use Docker vs VMs for Databases
It’s a common debate: Can Docker run my production database or should I use a VM instead? Keep reading to find out, but before we get started, check out CBT Nugget’s Docker training, Kubernetes Swarm tutorials and VM management guides if this is new territory for you. Those courses will make this article easier to understand.
Docker vs. VMs
Docker containers and VMs are two very different things. You need to know the differences between both before going any further.
Containers are not virtualized apps. They are apps thrown in jail, locked away from everything else, never to see the light of day again. Containers run on bare metal like any other application. However, applications inside the container can’t reach beyond the confines of the container. Containers carry just enough resources with them to allow apps to run inside them without needing outside access. This has the added benefit of making containers portable.
On the other hand, think of VMs as people locked behind a gated community, who take resources from the broader neighborhood and keep them for themselves. VMs are greedy. They don’t like to share, and they aren’t easily moved. However, they are self-reliant, have little complexity, and are generally very stable.
Docker vs. VM: Which is Better for Databases?
Both Docker containers and VMs are great options for hosting databases. Like all tools, though, each has its utility. Both containers and VMs can perform extremely well or slower than molasses. The performance of both boils down to how well you know the tool. Both containers and VMs can be tuned to power databases blazingly fast.
So, What’s the Difference?
Docker Containers Are Portable
Remember that bit above about Docker containers being portable while VMs aren’t? That’s the difference, but that also has many connotations. Databases are full of all sorts of state. Docker containers are designed to be stateless. That’s contradictory.
Containers are designed to return to their original state when powered down. Yes, containers can maintain state, but this process requires additional steps. A container’s state is essentially saved outside the container and reloaded each time the container is started again.
On the other hand, VMs are virtualized computers inside of a computer. When the VM powers down, it’s treated like a normal computer. The VM maintains a normal state.
Databases are designed to keep running without offloading data. The nature of a Docker container goes against the very nature of a database.
Containers Auto-Scale, but VMs Don’t
That said, many people and businesses run production databases inside Docker containers. It’s an acceptable practice. Some companies require it. Because containers are so portable and easily cloned, they can be managed with auto-scaling tools. If a production application needs more resources, that’s not a problem. The management app can easily spin up another copy of the database.
VMs are rock solid, however. In a production environment, it’s wise to introduce as little complexity as possible. It’s far less likely that a system will break if it has fewer moving pieces. Likewise, if engineers don’t need to orchestrate operations between multiple machines, they won’t ever need to worry about things like data syncing.
Which Databases Are Better In Containers?
There’s the database itself to consider, too. Some types of databases are better suited for containers. For example, Mongo and Redis are good container candidates. Mongo is designed to scale horizontally, while Redis is a straight-up greedy memory monster designed to flush data after short periods.
SQL is a different beast. SQL likes to scale vertically by introducing more horsepower. SQL doesn’t want to be moved or split across multiple platforms. SQL is a better candidate for VMs.
Containers vs. VMs: Which is Better for Databases?
So, when choosing containers versus VMs for a database, that decision boils down to your use case. If you’re developing your application or targeting auto-scaling architectures, work with containers. If your production environment can’t risk adding complexity or requires the best possible stability, go with a VMs.
Ready to learn more? We offer online training courses that explain, how to create containers, VM management tutorials, and guides on mastering Docker with Kubernetes and Swarm. If you're not already a CBT Nuggets subscriber, try it out for free.
delivered to your inbox.
By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.