Docker Swarm (KB)
Copyright © 2004-2018 by NobleProg Limited All rights reserved.
This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise.
firstname.lastname@example.org tel: +44 20 7558 8274
Docker Swarm mode
- Docker Swarm is a native clustering tool that turns a group of Docker engines into a single, virtual Docker Engine.
- When you run Docker Engine outside of swarm mode, you execute container commands.
- When you run the Engine in swarm mode, you orchestrate services.
- Key futures
- Cluster management integrated with Docker Engine
- Declarative service model (scaling, desired state reconciliation, rolling updates)
- Multi-host networking
- Requirements - 3 networked VM's
- first one with docker-machine installed, all commands should be executed in terminal on this member
- two others (server-s1, server-s2) with docker engine
- Create cluster manager
$ eval $(docker-machine env server-s0) $ docker swarm init --advertise-addr 188.8.131.52
- Check cluster state and list of nodes
$ docker info $ docker node ls
- Add another node to the cluster
$ docker swarm join-token worker $ eval $(docker-machine env server-s1) $ docker swarm join --token SWMTKN-1-3nt...sfe 10.0.2.10:2377
- Create, inspect and scale service called training
$ eval $(docker-machine env server-s0) $ docker service ls $ docker service create --replicas 1 --name training kamilbaran/nobleprog_training:training_app_v1 $ docker service inspect --pretty training $ docker service ps training $ docker ps $ docker service scale training=5
- Rolling update of a service
$ docker service update --update-delay 7s training $ docker service update --image kamilbaran/nobleprog_training:training_app_v2 training $ docker service inspect --pretty training $ docker service ps training
- Ingress network and routing mesh
$ docker service create --name training-app --publish 80:80 --replicas 1 kamilbaran/nobleprog_training:training_app_v1 $ docker service ps training-app $ curl server-s0 $ curl server-s1 $ while :; do ((i++)); curl --connect-timeout 1 server-s0/?count=$i; sleep 1; done
- Removing a service and a node
$ docker service rm training training-app $ docker node rm server-s2