Original article, welcome to reprint. Reprint please specify: reprint from IT people story, thank you! The original link address: “intermediate” docker – the level of Service to create maintenance and extension of swarm (45)
Having created 1 Manager and 2 workers from the previous section, let’s see how to use them. Source code address: github.com/limingios/d… The No. 5;
The operation of the service
Said before docker – compose the mentioned service, a service is a container vessel, and service in the swarm is a container that may be running in our clus above any a node.
- Docker-swarm docker swarm docker service
Docker service create and Docker run are basically the same command. Docker runs are not used under Swarm. Docker runs are created locally. The Docker containers we create under CLUS don’t necessarily run on that machine. So docker run is basically out of use.
docker service --help
docker servcie create
docker run
Copy the code
- Create a swarm demo container
docker service create --name demo busybox sh -c "while true; do sleep 3600; done"
docker service ls
This container is currently running on swarm-worker1, which is all random.
docker service ps demo
Copy the code
docker service ls
Copy the code
- Horizontal and horizontal expansion
Scale horizontally to 5 containers
docker service scale demo=5
docker service ls
docker service ps demo
Copy the code
- Automatic recovery function
We will first go to Worker2 to forcibly delete, then check the situation of manager, and later check the situation of Docker service ls by command
# drop container in docker-work2
docker rm -fContainer ID in container 2# check in docker-manager, there are only 4 normal operation
docker service ls
Docker-work2 container has been shutdown
docker service ps demo
Copy the code
After a few seconds in view of the container operation, automatically reply to the previously requested 5.
# Check in docker-manager, there are only 5 normal operation
docker service ls
The docker-work2 container has been shutdown
docker service ps demo
Copy the code
- Effect of deleting service
docker service rm demo
Copy the code
PS: Docker service has a lot of complicated operations inside. Although you use a simple one to create and delete, the bottom layer will know that there are multiple containers on that machine, and the container applications in these machines run those commands, which plays a role in cluster management.