Docker Swarm (KB)

From Training Material
Jump to navigation Jump to search


Author


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 11.0.2.10
  • 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