Docker 1.12 and swarm mode
-
Upload
wesley-charles-blake -
Category
Technology
-
view
182 -
download
0
Transcript of Docker 1.12 and swarm mode
Docker 1.12 and SwarmPresented By : Wesley Blake | Technical Director @Prop Datahttp://blog.stratotechnology.com/intro-to-docker-1-12-and-swarm-mode/https://github.com/WesleyCharlesBlake
Feature highlights
● Cluster management integrated with Docker Engine● Decentralized design● Declarative service model● Scaling● Desired state reconciliation● Multi-host networking● Service discovery● Load balancing (Container-native load balancing.)● Secure by default (Automated key rotation.)● Rolling updates
swarm
● A swarm is a cluster of Docker Engines.● Swarm mode is native in Docker 1.12 RC.● When in swarm mode, you orchestrate
services.
$ docker swarm
Usage: docker swarm COMMAND
Manage Docker Swarm
Commands: init Initialize a swarm join Join a swarm as a node and/or manager join-token Manage join tokens update Update the swarm leave Leave a swarm
node
● A node is a Docker Engine and a member of the swarm.● There are two types of nodes, managers and workers.● A manager node schedules service tasks on worker nodes.● Manager nodes and worker nodes are both capable of executing
tasks.
$ docker node
Usage: docker node COMMAND
Manage Docker Swarm nodes
Commands: demote Demote a node from manager in the swarm inspect Display detailed information on one or more nodes ls List nodes in the swarm promote Promote a node to a manager in the swarm rm Remove a node from the swarm ps List tasks running on a node update Update a node
{service,task}
● A service defines tasks that are executed in the swarm.
● service = image + command● A task is the scheduling and
execution of a service on a node.
$ docker service
Usage: docker service COMMAND
Manage Docker services
Commands: create Create a new service inspect Display detailed information on one or more services ps List the tasks of a service ls List services rm Remove a service scale Scale one or multiple services update Update a service
Swarm CLI
$ swarm init$ swarm join$ service create$ service inspect$ service ls$ service ps$ service rm$ service scale$ service update
Let’s create a swarm cluster
*Native docker swarm needs hosts to run docker 1.12*
$ docker-machine create -d virtualbox manager1$ docker-machine create -d virtualbox worker1$ docker-machine create -d virtualbox worker2$ docker-machine create -d virtualbox worker3$ docker-machine lsNAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORSmanager1 - virtualbox Running tcp://192.168.99.100:2376 v1.12.0 worker1 - virtualbox Running tcp://192.168.99.101:2376 v1.12.0 worker2 - virtualbox Running tcp://192.168.99.102:2376 v1.12.0 worker3 - virtualbox Running tcp://192.168.99.103:2376 v1.12.0
swarm init
$ eval $(docker-machine env manager1) $ docker swarm init \ --advertise-addr $(docker-machine ip manager1) \ --listen-addr $(docker-machine ip manager1):2377
# or ssh directly onto the host:
$ docker swarm init \ --advertise-addr 192.168.99.100 \ --listen-add 192.168.99.100:2377
swarm join
$ docker swarm join-token workerTo add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-4x502sygb5ws0wwmpevndnp4d55bbxsmts339ylpuh37kiy5sv-dl7jurksix80niuo2ncj9v0ak \ 192.168.99.100:2377
$ docker swarm join-token managerTo add a manager to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-4x502sygb5ws0wwmpevndnp4d55bbxsmts339ylpuh37kiy5sv-79ugs5f3pwvv5jrom5b8dinhs \ 192.168.99.100:2377
$ docker node lsID HOSTNAME STATUS AVAILABILITY MANAGER STATUS97zmo0c36dfj675dpg2q2rtg0 worker2 Ready Active c0q0ckwe3h39fbu9sv33069fo worker3 Ready Active cjzcy20zu8uarq6g2l8z4eg9n * manager1 Ready Active Leaderdmt4kjgeeem6bsqb2jcmvzuj1 worker1 Ready Active
service {create,inspect,ls}
docker service create \ --replicas 1 \ --name vote \ -p 8080:80 \ --network go-demo \ --update-delay 10s \ --update-parallelism 2 \ instavote/vote
$ docker service lsID NAME REPLICAS IMAGE COMMAND1q10x534o7r7 vote 4/4 instavote/vote
$ docker service inspect --pretty vote
ID: 1q10x534o7r75eji2lvt32atuName: voteMode: Replicated Replicas: 4Placement:UpdateConfig: Parallelism: 2 Delay: 10s On failure: pauseContainerSpec: Image: instavote/voteResources:Networks: 52l8ayurqgh3a7937e7pcrttkPorts: Protocol = tcp TargetPort = 80 PublishedPort = 8080
service ps
$ docker service ps vote
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR4a4kv8mul0z87l5xx6aetkcnq vote.1 instavote/vote worker1 Running Running 7 minutes ago 6p7bofib6y44ew4olsssqn1ht vote.2 instavote/vote worker2 Running Running 8 minutes ago 3s2cqdwdp57p5ehmtqggcj7kq vote.3 instavote/vote worker3 Running Running 8 minutes ago 2pbv6a7y2x0e74v85c61r5k41 vote.4 instavote/vote manager1 Running Running 7 minutes ago
DEMO this thing!
service scale
$ docker service scale vote=8vote scaled to 8
$ docker service lsID NAME REPLICAS IMAGE COMMAND1q10x534o7r7 vote 8/8 instavote/vote
$ docker service scale vote=8 redis=3vote scaled to 8
$ docker service lsID NAME REPLICAS IMAGE COMMAND1q10x534o7r7 vote 8/8 instavote/vote 9sjd1xLX781a redis 3/3 redis
service update
docker service update --image instavote/vote:movies vote # can result in down time during the update
# perform a rolling update:docker service update --update-parallelism 2 --update-delay 5s --image instavote/vote:movies vote#updates 2 tasks simultaneously, delay of 5s between update,