Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build a cluster in docker

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to build a cluster in docker". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Create a cluster

A cluster consists of multiple nodes, which can be physical or virtual machines. It is simple to run docker swarm init to enable cluster mode and make your current machine a cluster manager, and then run docker swarm join on other machines to join the cluster as workers.

Next, to quickly create a cluster using a virtual machine, you need a hypervisor that can create a virtual machine (VMs) and install the Oracle VirtualBox application on the machine. If you have a Windows 10 system and you have Hyper-V installed, you don't need to install VirtualBox, you should use Hyper-V instead.

Now, use docker-machine to create several virtual machines and use the VirtualBox driver:

$docker-machine create-- driver virtualbox myvm1 $docker-machine create-- driver virtualbox myvm2

Now that you have created two virtual machines named myvm1 and myvm2, list the machines and obtain their IP addresses using the following command:

$docker-machine ls

The first machine will act as an administrator, execute management orders and certify workers to join the group, and the second machine will become a worker. You can use docker-machine ssh to send commands to the virtual machine, and execute docker swarm init to make myvm1 the cluster manager:

$docker-machine ssh myvm1 "docker swarm init-advertise-addr"

After docker swarm init is executed, a preconfigured docker swarm join command is included in the response, which can be run on any node you want to add. Copy this command and send it through docker-machine ssh to a virtual machine named myvm2, allowing myvm2 to join the new cluster as a worker:

$docker-machine ssh myvm2 "docker swarm join-token: 2377"

When joining myvm2 to the cluster, choose 2377 as port 2376 is a Docker daemon port, do not use this port, or you may encounter an error. Run docker node ls on the manager to view the nodes in the cluster:

$docker-machine ssh myvm1 "docker node ls"

Now that the cluster has been created, if you want to delete the cluster, you can run it on each node using docker swarm leave.

This is the end of "how to build a cluster in docker". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report