10. Create Database and Insert some data in the Primary Container
Exit and exec again. Then Login using mysql db cli
mysql -u clusteradmin -p
Then Create a Database
CREATE DATABASE developer;
use developer;
Create a Table
CREATE TABLE dev(name VARCHAR(20) NOT NULL, SLNO INT NOT NULL, PRIMARY KEY(SLNO));
DESCRIBE dev;
Insert Data
INSERT INTO dev VALUE("dev1",1);
11. Exec into secondary container & check the data.
SELECT * from developer.dev
You can see the data that you inserted from primary container as the data will be replicated automatically. That means, You have successfully created the DB Cluster in Docker!!!!
Why Do You Need a DB Cluster in Docker
Using a MySQL database cluster in a Docker environment can provide several benefits, particularly in terms of scalability, flexibility, and ease of management. Here are some of the key advantages:
Scalability:
Horizontal Scaling: Docker makes it easy to deploy multiple instances of MySQL databases, allowing for horizontal scaling. This is crucial for handling increased workloads as your application grows.
Container Orchestration: Container orchestration tools like Kubernetes can be used to manage and scale MySQL containers dynamically based on demand.
Flexibility:
Consistent Environment: Docker containers encapsulate the application, dependencies, and configuration, ensuring a consistent environment across different stages of development, testing, and production.
Isolation: Each MySQL instance runs in its own container, providing isolation. This isolation makes it easier to manage dependencies and avoids conflicts between different versions of MySQL or other software.
Efficient Resource Utilization:
Resource Isolation: Docker containers share the host OS kernel, making them lightweight compared to virtual machines. This results in more efficient use of resources and allows running multiple MySQL instances on the same host without significant overhead.
Easy Deployment and Rollback:
Containerization: Packaging MySQL as a container allows for easy deployment across various environments, reducing the likelihood of "it works on my machine" issues.
Rollback Capabilities: Docker allows for versioning of container images, enabling straightforward rollback to a previous version if issues arise during an update.
Rapid Development and Testing:
DevOps Practices: Docker facilitates DevOps practices by streamlining the development and testing process. Developers can work in a containerized environment that mirrors production, reducing the chances of discrepancies between environments.
Isolation and Security:
Isolation of Processes: Containers provide process isolation, ensuring that each MySQL instance runs independently.
Security Updates: Docker allows you to update individual containers without affecting the entire system, making it easier to apply security patches.
High Availability and Fault Tolerance:
Replication and Clustering: MySQL clusters can be set up using Docker Compose or Kubernetes, providing high availability and fault tolerance.
Automated Failover: Tools like Orchestrator or ProxySQL, when combined with Docker and container orchestration, can automate failover processes in the event of a node failure.
Infrastructure as Code (IaC):
Declarative Configuration: Docker Compose or Kubernetes configurations can be used to declare the desired state of the MySQL cluster. This aligns with Infrastructure as Code principles, making infrastructure configurations version-controlled and reproducible.
Reduced Development Time:
Quick Setup for Developers: Developers can quickly set up a MySQL cluster locally using Docker containers, reducing the time needed for environment configuration.
Cost-Effective:
Resource Efficiency: Docker's efficient resource utilization allows for running multiple containers on the same host, potentially reducing infrastructure costs.
While using MySQL clusters in Docker brings numerous benefits, it's essential to carefully plan the deployment, consider data persistence, and implement appropriate backup and recovery strategies to ensure the reliability and availability of your database systems.
Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here
Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here
Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here
I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
0 comments:
Post a Comment