Running MySQL in containers is now completely normal. The real question most teams struggle with isn't “Should we containerize MySQL?” - it's:
Do we use Docker or Kubernetes to run it reliably in production?
There’s no universal right answer. Docker shines for speed and simplicity. Kubernetes is built for automation and resilience at scale. This guide walks through both options in practical terms - how they behave, where they fit best, and what trade-offs you should expect - so you can choose what actually fits your team and workload.
The Reality of Running Databases in Containers
Containers work beautifully for apps that can be restarted at any time. Databases are different. They hold state, history, and consistency - and that makes them harder to manage in a dynamic environment.
The main challenges teams run into are:
- Data must survive restarts - You can’t afford to lose data just because a container restarts.
- The database has “memory” - Its internal state matters and must stay consistent.
- Nodes must find each other reliably - Replication depends on stable connections.
- Some actions must happen in order - Starting, stopping, scaling, and upgrading all need coordination.
Both Docker and Kubernetes solve these problems - but at very different levels of sophistication.
Common MySQL Clustering Options (Quick Context)
Before talking about orchestration, it helps to know what usually runs inside the containers:
- MySQL InnoDB Cluster - MySQL’s built-in high-availability solution.
- Galera Cluster - Synchronous multi-master replication.
- MySQL NDB Cluster - Distributed, shared-nothing architecture.
- Tungsten Cluster - Advanced replication, failover, and zero-downtime operations.
Your orchestration platform determines how easy or hard it is to deploy, operate, and recover any of these.
Docker: Fast, Simple, and Familiar
Docker Compose: The Quickest Way to a Working Cluster
Docker Compose is often the fastest way to get a MySQL cluster running. You describe your services in a single file, run one command, and everything starts.
In plain terms, it lets you say:
- “Here is my primary database.”
- “Here is my replica.”
- “Here is where the data should be stored.”
- “Here is how they connect.”
And Docker handles the rest.
Why teams like it:
- Extremely fast to set up.
- Very easy to understand.
- Works great on laptops and test servers.
- Low resource overhead.
- Perfect for development and demos.
How data survives container restarts:
Docker uses volumes to store MySQL data outside the container, so even if the container is recreated, the database files remain intact.
Docker Swarm: When You Need More Than One Machine
Docker Swarm takes the same Docker tools and spreads them across multiple servers. It adds:
- basic high availability;
- automatic service restarts;
- built-in load balancing;
- rolling updates;
- multi-host networking.
It’s often used as a stepping stone between simple Docker setups and full Kubernetes platforms.
Where Docker Starts to Struggle in Production
Docker’s simplicity is also its main limitation for serious production databases:
- If the host fails, everything on it fails too.
- Scaling often requires manual intervention.
- Health checks are basic.
- Failover logic is minimal.
- Backups and recovery are largely DIY.
- There’s no built-in understanding of how a database behaves.
In practice, many experienced teams use Docker heavily for development and testing, but move away from it for mission-critical production databases.
Kubernetes: Built for Long-Running, Self-Healing Systems
Kubernetes was designed specifically for highly available, always-on systems - including databases. It continuously watches your environment and actively works to keep your desired state intact.
What that means in everyday terms:
- If something crashes, it restarts automatically.
- If a server dies, workloads move elsewhere.
- If you scale up, Kubernetes handles placement.
- If you upgrade, it can roll updates with minimal disruption.
Why MySQL on Kubernetes Is Different
Stable Identities for Database Nodes
Kubernetes gives each MySQL instance a stable name and identity. This is essential for replication and failover - the database always knows “who is who,” even after restarts.
Storage That Survives Failures
Each MySQL instance gets its own persistent storage that follows it if the pod is rescheduled. This allows Kubernetes to move databases between nodes without losing data.
Ordered Startup and Shutdown
Kubernetes knows which database node must start first, which one is next, and how to safely stop them. This prevents many common corruption and split-brain scenarios.
MySQL Operators: Let Kubernetes Run the Database for You
The biggest difference between “running MySQL on Kubernetes” and “running MySQL well on Kubernetes” is the use of Operators.
Operators are automation layers that encode real database operational knowledge. Instead of scripting everything manually, you simply describe what you want, and the Operator does the hard work.
With an Operator, Kubernetes can automatically handle:
- cluster creation;
- replication setup;
- failover and recovery;
- scaling;
- backups;
- rolling upgrades.
What used to require long operational playbooks becomes a few configuration files and policies.
What Happens When Something Fails in Kubernetes?
Here’s what automatic recovery really looks like in practice:
- A MySQL container crashes.
- Kubernetes detects it immediately.
- The container is restarted.
- If the whole server fails, the database is moved elsewhere.
- The storage is reattached automatically.
- The Operator repairs replication.
- Applications reconnect without manual intervention.
This is the core reason enterprises adopt Kubernetes for databases: failure becomes routine instead of catastrophic.
Docker vs Kubernetes: The Big Picture
At a High Level
| Docker (Compose / Swarm) | Kubernetes |
|---|---|
|
Local development Testing Small deployments Teams that value simplicity over automation |
Production-critical systems High availability and self-healing Automated operations at scale Multi-region and multi-cloud deployments |
The Real Trade-Off
| Docker (Compose / Swarm) | Kubernetes | |
|---|---|---|
| Gives you |
Speed Simplicity Minimal overhead |
Far higher resilience Automated recovery Advanced scaling and upgrades |
| It requires |
Limited automation Less protection against failures More manual work as systems grow |
More infrastructure Deeper expertise Higher operational maturity |
How to Choose in Practice
Docker Is a Great Fit When:
- You’re working locally or in CI/CD.
- Your team is small and moves fast.
- You don’t need automated failover.
- Downtime is inconvenient, but not disastrous.
- You want the simplest possible setup.
Kubernetes Is the Right Choice When:
- Your system is business-critical.
- Downtime has real financial or legal impact.
- You need automated failover and recovery.
- You operate at scale.
- You already have DevOps/SRE expertise.
- You require compliance, backups, and auditability.
Many teams successfully use both:
- Docker for development and testing.
- Kubernetes for production.
This keeps developer velocity high without sacrificing production reliability.
Practical Best Practices
If You Use Docker
- Always separate database data from the container itself.
- Limit how much CPU and memory MySQL can use.
- Don’t treat backups as optional - Docker won’t do this for you.
- Regularly test restoring from backups.
- Assume you’ll need a more robust platform later.
If You Use Kubernetes
- Use the tools designed for databases, not generic app tools.
- Let Operators handle replication and failover.
- Spread database nodes across different servers.
- Plan upgrades as rolling operations.
- Monitor everything from day one.
- Never hardcode passwords in configuration files.
Final Takeaway
This isn’t a battle between Docker and Kubernetes. It’s a question of scale, risk, and operational maturity.
- If you need speed and simplicity, Docker is often the right answer.
- If you need automation, resilience, and long-term stability, Kubernetes is the better foundation.
Start with what fits your current reality - but design your architecture so you can grow without rebuilding everything later.
Comments
Add new comment