
Ruben's Blog | ΥΥΈΦΥ’Υ₯ΥΆΥ« Τ²Υ¬ΥΈΥ£Υ¨
π ..Dockerized Mysql Cluster With Swarm ππ³π
Docker Swarm is a good choice for smaller and simpler Dockerized MySQL clusters due to its ease of use and compatibility with Docker. On the other hand, Kubernetes offers advanced features and scalability for larger and more complex deployments, but requires a higher level of knowledge and infrastructure. Ultimately, choose the best option based on your application’s specific needs.
In this article, we’ll explore the deployment of a 3-node InnoDB cluster using Docker Swarm. The cluster will consist of three MySQL nodes, each running on a separate server. We’ll take a deep dive into the process of setting up Docker Swarm, configuring the MySQL nodes, and deploying the cluster. By the end of this article, you’ll have a solid understanding of how to use Docker Swarm to deploy a MySQL cluster, and you’ll be ready to tackle similar projects on your own.
π¨ Be careful when using Dockerized databases! π¨
π₯ Containers can be a fire hazard if not properly secured, leading to potential data loss or breaches.
For our deployment of the 3-node InnoDB cluster using Docker Swarm, we have two main strategies to consider for setting up the necessary directories.
- The first strategy involves configuring NFS on any number of machines and adding one more server for NFS.
- The second strategy involves creating dedicated directories for each server we will use, and forcing Docker to run on the servers we want to make it replicate bare metal deployment.
For our purposes, we’ll be using the second strategy. This approach will allow us to have more control over the deployment, and ensure that each server has its own dedicated directory for the MySQL data. Let’s take a closer look at the steps involved in this approach.
Note about env vars
To distribute environment variables to all containers in a Docker Swarm cluster, you should embed them in the Docker Compose file. This is necessary because environment files are not distributed across all nodes in the cluster.
This is not very elegant but we will get back to this in another post probably.
repo with source codes example
Please pull the repository from here https://github.com/shekspir55/mysql-docker-compose-examples
less talk more work
create directories in the servers
mkdir /mysql-data
docker swarm init
Follow instructions to set up secondary swarm instances.
Add labels to swarm nodes, this is needed to force nodes to run on the swarm nodes we want.
# take ids from the output to input in the commands below
docker node ls
#for master swarm instance
docker node update --label-add type=leader ID-GOES-HERE
#for master secondary instances
docker node update --label-add type=mysql-worker-2 ID-GOES-HERE
#for master secondary instances
docker node update --label-add type=mysql-worker-3 ID-GOES-HERE
docker stack deploy -c ./docker-compose.yml cluster
to debug docker swarm if something goes wrong and node doesn’t start
docker service ls
- to get all services which are suppose to run.
docker service ps --no-trunc ID-OF-CONTAINER-NOT-STARTING
now check mysql-shell logs for results
βοΈ read next: Tips on troubleshooting Docker Image build, Compose and Swarm issues π³π³π³
references:
Please give me feedback or make a comment on whatever help me improve. β€οΈ
Blog Menu
- πΌ hire my consultancy
- βΉοΈ about me
- π° rss
- βοΈ Spend a day with me
- tech and life
- π blogs
- 2025-05-16
Spending 5 Minutes to Make a Point π
This blog post is an exercise. I want to make a point, and for that, I will need to do some research and tell a story. Telling a story Henry Ford was ...
- 2025-05-14
Non technical founders, Visionary Builders Community π―ββοΈ
This is my third community. I’m starting to understand how it works. People with similar interests or challenges tend to have similar insights a...
- 2025-05-13
2nd CTO Event Is Soon πͺ
What’s about it? I host Armenian CTO Community. We have already 109 members there. First event hosted 21 members! I am doing this for over 9 mo...
- 2025-05-12
Reducing the Friction to Post πͺοΈ
Eliminating the reasons I don’t blog, one by one. Opening the editor is a friction, writing is a friction, pushing is a friction, but I can make...
- 2025-05-07
Consistency and Time β²οΈ
Do I have time to blog? Every time I wrote I will blog every day, I’ve reflected on this commitment in several posts: In I Need to Revisit My Bl...
- 2024-12-29
Then the Journey Is Not About Winning ποΈ
Winning is the target, but the journey is never about winning. You cannot be sure the path is correct. Even with guidance, there is a chance it’...
- 2024-12-28
Free Consultancy ππ»
Nobody buys it. When I provide it everyone is happy. Why? Maybe people don’t understand the offer, which is completely understandable. What I of...
- 2024-12-28
The Algorithm of the Dressings π₯¬βπ₯ββοΈπ°π₯
Martun said he read many books about healthy food and didn’t become healthy. I agree, that reading and doing is very different. But I think that...
- 2024-12-25
Powered.community Meetup π€π»
Well, it happened. The food was sushi, and people came with friends, some just checking in. I was so glad to see so many people I know and don’t...
- 2024-12-23
5 Books to Read Before 2025 to Transform Your Life ποΈ
People are not computers, though we share traits such as short and long-term memory or processing power. You cannot install a “software” o...
- See all...
- π links