Slides
-
Show options:
docker swarm --help
-
Single node swarm:
docker swarm init
-
Show information:
docker info
-
Leave swarm:
docker swarm leave
anddocker swarm leave -f
Slides
Complete script to create the cluster: swarm-cluster.sh
-
docker-machine -v
-
Pre-create 6 Docker Machines using
swarm-machines.sh
-
Show list of machines:
docker-machine ls
-
Initialize swarm mode on
manager
:docker-machine ssh manager1 \ "docker swarm init \ --listen-addr $(docker-machine ip manager1) \ --advertise-addr $(docker-machine ip manager1)"
-
Show list of nodes:
docker-machine ssh manager1 "docker node ls"
-
Get manager token:
docker-machine ssh manager1 "docker swarm join-token manager -q"
-
Get worker token:
docker-machine ssh manager1 "docker swarm join-token worker -q"
-
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)"
-
Show list of nodes:
docker-machine ssh manager1 "docker node ls"
-
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)"
-
Show list of nodes:
docker-machine ssh manager1 "docker node ls"
-
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)"
-
Show list of nodes:
docker-machine ssh manager1 "docker node ls"
-
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)"
-
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)"
-
Show list of nodes:
docker-machine ssh manager1 "docker node ls"
-
Show cluster information:
docker-machine ssh manager1 "docker info"
Slides
-
In
manager1
, see the nodes where containers are running:docker service ps web
-
SSH to a node where the container is running. Show the list of containers:
docker container ls
-
Exit out of
manager1
-
Show the number of replicas:
docker-machine ssh manager1 "docker service ls"
-
Kill a container:
docker-machine ssh <node> "docker container rm -f <cid>"
-
<node>
is where the container is running -
<cid>
is the id of the container
-
-
Show the replicas in service:
docker-machine ssh manager1 "docker service ls"
-
Show that only 2 replicas are running and reconciliation happens by swarm manger
-
-
Show the list of nodes:
docker-machine ls
-
Show the node where containers are running:
docker-machine ssh manager1 "docker service ps web"
-
Show number of replicas for the service:
docker-machine ssh manager1 "docker service ls"
-
Stop a node where the container is running:
docker-machine stop <node>
-
Show the list of nodes:
docker-machine ls
-
Show the services:
docker-machine ssh manager1 "docker service ls"
-
Show how desired vs actual is reconciled:
docker service ls
-
Show how container is started on a different node:
docker service ps web
Slides
-
List service and replicas:
docker ssh manager1 "docker service ls"
-
Show node where containers are running:
docker ssh manager1 "docker service ps web"
-
Use filters to restrict output:
docker-machine ssh manager1 "docker service ps -f \"desired-state=running\" web"
-
SSH to
manager
:docker-machine ssh manager1
-
Check the list of running services again:
docker service ps -f "desired-state=running" web
-
Scale service:
docker service scale web=6
-
Shutdown service:
docker service rm web
-
Show the list of services:
docker service ls
-
Create 6 replicas of a service:
docker service create --name webapp --replicas 6 -p 8080:8080 arungupta/wildfly-app:1
-
Check service:
docker service ls
-
Check tasks in the service:
docker service ps webapp
. Show the version of image in each app. -
Access the application http://192.168.99.100:8080/app/index.jsp and show green background
-
Rolling update service:
docker service update webapp --image arungupta/wildfly-app:2 --update-parallelism 2 --update-delay 10s
-
Check status every 5 secs:
docker service ps webapp
-
Access the application http://192.168.99.100:8080/app/index.jsp and show red background
-
Show the list of services:
docker service ls
-
Remove service
docker service rm webapp
-
Login to
manager1
:docker-machine ssh manager1
-
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
-
Deploy:
docker stack deploy --compose-file=docker-compose.yml webapp
-
docker stack ls
-
docker service ls
-
docker service ps webapp_web
- show the node where the container is running -
docker service ps webapp_db
- show the node where the container is running -
See the logs of
web
service-
Log in to the node where container is running:
docker-machine ssh <node-name>
-
See the list of containers:
docker container ls
-
View logs:
docker container logs <cid>
-
Alternatively (only on experimental)
docker service logs webapp_web
-
-
Access the application
curl -v http://$(docker-machine ip <node>):8080/airlines/resources/airline
-
Remove stack:
docker stack rm webapp
Slides
-
Go to docker.com/getdocker
-
Launch the template and explain the creation and parameters
-
SSH into instance:
ssh -i ~/.ssh/arun-docker.pem docker@<master-ip>
-
Show more details:
docker info
-
Show node listing:
docker node ls
-
Setup SSH tunnel:
ssh -i ~/.ssh/arun-docker.pem -NL localhost:2374:/var/run/docker.sock docker@<master-ip>
-
Show cluster information:
docker -H localhost:2374 info