In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces you how to understand service in Swarm mode, the content is very detailed, interested friends can refer to, hope to be helpful to you.
We show you how to operate service.
Service, we should be no strangers. We have talked about this before. A service corresponds to a container container. When we used docker compose, a service was deployed on a machine. But we are under swarm, and when we create a service, it may run on any node in our cluster, as described below.
Docker service command
Docker service create is a bit like docker run.
Under swarm, we do not apply the docker run command to run the container. Docker run means to create a container locally. Service does not necessarily run locally. Therefore, under swarm, docker run is generally not used.
We use to create a service:
Vincent@swarm-manager:~$ docker service create-- name demo busybox sh-c "while true; do sleep 3600 done" lf0wx1k2xz3l88mandyifkdm7overall progress: 1 out of 1 tasks1/1: runningverify: Service converged
Check the service situation:
Vincent@swarm-manager:~$ docker service lsID NAME MODE REPLICAS IMAGE PORTSlf0wx1k2xz3l demo replicated 1/1 busybox:latest
So which node does the service run on?
Vincent@swarm-manager:~$ docker service ps demoID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTShkgsjp3dswfh demo.1 busybox:latest swarm-worker-1 Ready Ready 3 seconds ago
The description runs on swarm-worker-1.
MODE replicated indicates that the service is scalable horizontally.
How to expand?
Docker service scale demo=5
Vincent@swarm-manager:~$ docker service scale demo=5demo scaled to 5overall progress: 5 out of 5 tasks1/5: running2/5: running3/5: running4/5: running5/5: runningverify: Service convergedvincent@swarm-manager:~$ docker service lsID NAME MODE REPLICAS IMAGE PORTSlf0wx1k2xz3l demo replicated 5/5 busybox:latest
You can see that five service have been successfully extended. The denominator indicates what the scale of the service is, and how many of the numerators have been activated normally.
Vincent@swarm-manager:~$ docker service ps demoID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTSkvngsxo8q1jv demo.1 busybox:latest swarm-worker-2 Running Running 3 minutes agow9uw1zoncfki demo.2 busybox:latest swarm-worker- 1 Running Running 2 minutes agosxsro5dzepjc demo.3 busybox:latest swarm-manager Running Running 2 minutes agoklxhs3ec1j6c demo.4 busybox:latest swarm-manager Running Running 2 minutes agoyxov6fzvwsyr demo.5 busybox:latest swarm-worker-2 Running Running 2 minutes ago
You can see that there are two service on the swarm-worker-2 node, two service on the swarm-manager node and one on the swarm-worker-1 node.
Let's go to swarm-worker-1 to verify:
Vincent@swarm-worker-1:~$ docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESf1644c316b53 busybox:latest "sh-c 'while true;..." 3 minutes ago Up 3 minutes demo.2.w9uw1zoncfkikb1iayit9mdba
There is a container. Go to swarm-work-2 to verify:
Vincent@swarm-worker-2:~$ docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa0607b0aa4ad busybox:latest "sh-c 'while true;..." 4 minutes ago Up 4 minutes demo.5.yxov6fzvwsyrfue8q1redjyx99ccc6696214e busybox:latest "sh-c 'while true;..." 6 minutes ago Up 6 minutes demo.1.kvngsxo8q1jvd5mv6k9lcvxf1
There are two container. Go to swarm-manager to verify:
Vincent@swarm-manager:~$ docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES128053167c33 busybox:latest "sh-c 'while true;..." 5 minutes ago Up 5 minutes demo.4.klxhs3ec1j6cek8914lk5mhdtdd1dca1864dc busybox:latest "sh-c 'while true;..." 5 minutes ago Up 5 minutes demo.3.sxsro5dzepjc0mgs1phzz12ro
There are two container.
After expanding the service horizontally for 5 times, everything is normal.
What happens if I delete the container?
We delete a container in swarm-worker-2:
Vincent@swarm-worker-2:~$ docker rm- f 9ccc6696214e9ccc6696214e
Then check it on swarm-maganger:
Vincent@swarm-manager:~$ docker service lsID NAME MODE REPLICAS IMAGE PORTSlf0wx1k2xz3l demo replicated 5/5 busybox:latest
It's still five. But these are no longer the five containers they used to be.
Vincent@swarm-manager:~$ docker service ps demoID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTSvq4lgu31i4bn demo.1 busybox:latest swarm-worker-1 Running Running 3 minutes agokvngsxo8q1jv\ _ demo.1 busybox:latest Swarm-worker-2 Shutdown Failed 3 minutes ago "task: non-zero exit" w9uw1zoncfki demo.2 busybox:latest swarm-worker-1 Running Running 10 minutes agosxsro5dzepjc demo.3 busybox:latest swarm-manager Running Running 10 minutes agoklxhs3ec1j6c demo.4 busybox:latest swarm -manager Running Running 10 minutes agoyxov6fzvwsyr demo.5 busybox:latest swarm-worker-2 Running Running 10 minutes ago
As you can see, one of our containers on swarm-worker-2 is already shutdown, but one has been restarted on swarm-worker-1. So there are two container on swarm-worker-1.
Therefore, swarm not only ensures that it can scale out, but also guarantees a certain number of effective.
When swarm discovers that the service on some nodes in the scale fails, then he will restart one on any node in the cluster to reach the scale. It can ensure that the system is effective and stable.
Docker service rm demo
You can delete demo.
Vincent@swarm-manager:~$ docker service rm demodemo on how to understand the service in Swarm mode to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.