Skip to content

Latest commit

 

History

History
 
 

chapter4

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Chapter 4

4.1 Introduction to Swarm mode

Slides

  1. Show options: docker swarm --help

  2. Single node swarm: docker swarm init

  3. Show information: docker info

  4. Leave swarm: docker swarm leave and docker swarm leave -f

4.2 Create multi-node Swarm mode cluster using Docker Machine

Slides

Complete script to create the cluster: swarm-cluster.sh

  1. docker-machine -v

  2. Pre-create 6 Docker Machines using swarm-machines.sh

  3. Show list of machines: docker-machine ls

  4. Initialize swarm mode on manager:

    docker-machine ssh manager1 \
            "docker swarm init \
            --listen-addr $(docker-machine ip manager1) \
            --advertise-addr $(docker-machine ip manager1)"
  5. Show list of nodes: docker-machine ssh manager1 "docker node ls"

  6. Get manager token: docker-machine ssh manager1 "docker swarm join-token manager -q"

  7. Get worker token: docker-machine ssh manager1 "docker swarm join-token worker -q"

  8. Manager 2 joins cluster:

    docker-machine ssh manager2 \
            "docker swarm join \
            --token `docker-machine ssh manager1 "docker swarm join-token manager -q"` \
            --listen-addr $(docker-machine ip manager2) \
            --advertise-addr $(docker-machine ip manager2) \
            $(docker-machine ip manager1)"
  9. Show list of nodes: docker-machine ssh manager1 "docker node ls"

  10. Manager 3 joins cluster:

    docker-machine ssh manager3 \
            "docker swarm join \
            --token `docker-machine ssh manager1 "docker swarm join-token manager -q"` \
            --listen-addr $(docker-machine ip manager3) \
            --advertise-addr $(docker-machine ip manager3) \
            $(docker-machine ip manager1)"
  11. Show list of nodes: docker-machine ssh manager1 "docker node ls"

  12. Worker 1 join cluster:

    docker-machine ssh worker1 \
            "docker swarm join \
            --token `docker-machine ssh manager1 "docker swarm join-token worker -q"` \
            --listen-addr $(docker-machine ip worker1) \
            --advertise-addr $(docker-machine ip worker1) \
            $(docker-machine ip manager1)"
  13. Show list of nodes: docker-machine ssh manager1 "docker node ls"

  14. Worker 2 join cluster:

    docker-machine ssh worker2 \
            "docker swarm join \
            --token `docker-machine ssh manager1 "docker swarm join-token worker -q"` \
            --listen-addr $(docker-machine ip worker2) \
            --advertise-addr $(docker-machine ip worker2) \
            $(docker-machine ip manager1)"
  15. Worker 3 join cluster:

    docker-machine ssh worker3 \
            "docker swarm join \
            --token `docker-machine ssh manager1 "docker swarm join-token worker -q"` \
            --listen-addr $(docker-machine ip worker3) \
            --advertise-addr $(docker-machine ip worker3) \
            $(docker-machine ip manager1)"
  16. Show list of nodes: docker-machine ssh manager1 "docker node ls"

  17. Show cluster information: docker-machine ssh manager1 "docker info"

4.3 Deploying services to Swarm mode

Slides

Create service

  1. SSH to manager1: docker-machine ssh manager1

  2. Create a replicated service: docker service create --name web --replicas 3 -p 8080:8080 jboss/wildfly

  3. List service and replicas: docker service ls

  4. Inspect service: docker service inspect web

  5. List containers: docker service ps web

4.4 Container or Node failure

Slides

Container failure

  1. In manager1, see the nodes where containers are running: docker service ps web

  2. SSH to a node where the container is running. Show the list of containers: docker container ls

  3. Exit out of manager1

  4. Show the number of replicas: docker-machine ssh manager1 "docker service ls"

  5. Kill a container: docker-machine ssh <node> "docker container rm -f <cid>"

    1. <node> is where the container is running

    2. <cid> is the id of the container

  6. Show the replicas in service: docker-machine ssh manager1 "docker service ls"

    1. Show that only 2 replicas are running and reconciliation happens by swarm manger

Node failure

  1. Show the list of nodes: docker-machine ls

  2. Show the node where containers are running: docker-machine ssh manager1 "docker service ps web"

  3. Show number of replicas for the service: docker-machine ssh manager1 "docker service ls"

  4. Stop a node where the container is running: docker-machine stop <node>

  5. Show the list of nodes: docker-machine ls

  6. Show the services: docker-machine ssh manager1 "docker service ls"

  7. Show how desired vs actual is reconciled: docker service ls

  8. Show how container is started on a different node: docker service ps web

4.5 Scaling and rolling update of service

Slides

Scale service

  1. List service and replicas: docker ssh manager1 "docker service ls"

  2. Show node where containers are running: docker ssh manager1 "docker service ps web"

  3. Use filters to restrict output: docker-machine ssh manager1 "docker service ps -f \"desired-state=running\" web"

  4. SSH to manager: docker-machine ssh manager1

  5. Check the list of running services again: docker service ps -f "desired-state=running" web

  6. Scale service: docker service scale web=6

  7. Shutdown service: docker service rm web

  8. Show the list of services: docker service ls

Rolling update of service

  1. Create 6 replicas of a service: docker service create --name webapp --replicas 6 -p 8080:8080 arungupta/wildfly-app:1

  2. Check service: docker service ls

  3. Check tasks in the service: docker service ps webapp. Show the version of image in each app.

  4. Access the application http://192.168.99.100:8080/app/index.jsp and show green background

  5. Rolling update service: docker service update webapp --image arungupta/wildfly-app:2 --update-parallelism 2 --update-delay 10s

  6. Check status every 5 secs: docker service ps webapp

  7. Access the application http://192.168.99.100:8080/app/index.jsp and show red background

4.6 Multi-container application on multi-host cluster

  1. Show the list of services: docker service ls

  2. Remove service docker service rm webapp

  3. Login to manager1: docker-machine ssh manager1

  4. Create a new file docker-compose.yml and use the following content:

    version: '3'
    services:
      web:
        image: arungupta/couchbase-javaee:travel
        environment:
          - COUCHBASE_URI=db
        ports:
          - 8080:8080
          - 9990:9990
        depends_on:
          - db
      db:
        image: arungupta/couchbase:travel
        ports:
          - 8091:8091
          - 8092:8092
          - 8093:8093
          - 11210:11210
  5. Deploy: docker stack deploy --compose-file=docker-compose.yml webapp

  6. docker stack ls

  7. docker service ls

  8. docker service ps webapp_web - show the node where the container is running

  9. docker service ps webapp_db - show the node where the container is running

  10. See the logs of web service

    1. Log in to the node where container is running: docker-machine ssh <node-name>

    2. See the list of containers: docker container ls

    3. View logs: docker container logs <cid>

    4. Alternatively (only on experimental) docker service logs webapp_web

  11. Access the application curl -v http://$(docker-machine ip <node>):8080/airlines/resources/airline

  12. Remove stack: docker stack rm webapp

4.7 Node maintenance, label/constraints, global service

Slides only

4.8 Create multi-node Swarm mode cluster on AWS/Azure

Slides

  1. Go to docker.com/getdocker

  2. Launch the template and explain the creation and parameters

  3. SSH into instance: ssh -i ~/.ssh/arun-docker.pem docker@<master-ip>

  4. Show more details: docker info

  5. Show node listing: docker node ls

  6. Setup SSH tunnel: ssh -i ~/.ssh/arun-docker.pem -NL localhost:2374:/var/run/docker.sock docker@<master-ip>

  7. Show cluster information: docker -H localhost:2374 info