Saturday, February 25, 2017

Demonstrate Dockerswarm to create, add, deploy and inspect the service

Create a swarm

(Make sure the Docker Engine daemon is started on the host machines) Step1:Open a terminal and ssh into the machine where you want to run your manager node. Step2:$docker swarm init --advertise-addr 192.168.99.100 To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx\ 192.168.99.100:2377 To add a manager to this swarm, run "docker swarm join-token manager" and follow the instructions. Step3:Run docker info to view the current state of the swarm:$ docker info Step4:Run the docker node ls command to view information about nodes: $ docker node ls

Add nodes to the swarm 

(Once you've created a swarm with a manager node, you're ready to add worker nodes) Step5: Open a terminal and ssh into the machine where you want to run a worker node Step6: create a worker node joined to the existing swarm $ docker swarm join\ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx\ 192.168.99.100:2377 If you don't have the command available, you can run the following command on a manager node to retrieve the join command for a worker: $ docker swarm join-token worker Step7: Open a terminal and ssh into the machine where you want to run a second worker node[worker2] Step8: $ docker swarm join\ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0\ 192.168.99.100:2377 Step9:Open a terminal and ssh into the machine where the manager node runs. $ docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER 03g1y59jwfg7 worker2 Ready Active 9j68exjopxe7 worker1 Ready Active dxn1zf6l61qs * manager1 Ready Active Leader

Deploy a service to the swarm 

(After you create a swarm, you can deploy a service to the swarm. For this tutorial, you also added worker nodes, but that is not a requirement to deploy a service) Step1:Open a terminal and ssh into the machine where you run your manager node Step2:$ docker service create --replicas 1 --name helloworld alpine ping docker.com Step3:$ docker service ls //shows the list of running services

Inspect a service on the swarm 

(When you have deployed a service to your swarm, you can use the Docker CLI to see details about the service running in the swarm) Step1:If you haven't already, open a terminal and ssh into the machine where you run your manager node Step2:$docker service inspect --pretty helloworld //display the details about a service Step3:Run docker service ps <SERVICE-ID> to see which nodes are running the service: $docker service ps helloworld Step4:$ docker ps

Scale the service in the swarm 

(Once you have deployed a service to a swarm, you are ready to use the Docker CLI to scale the number of service ps in the swarm) Step1: If you haven't already, open a terminal and ssh into the machine where you run your manager node $docker service scale <SERVICE-ID>=<NUMBER-OF-TASKS> $docker service scale helloworld=5 Step2: Run docker service ps <SERVICE-ID> to see the updated task list: $ docker service ps helloworld Step3: Run docker ps to see the containers running on the node.

Delete the service running on the swarm 

Step1: If you havent already, open a terminal and ssh into the machine where you run your manager node $docker service rm helloworld Step2: Run docker service inspect <SERVICE-ID> to verify that the swarm manager removed the service: $docker service inspect helloworld

No comments:

Post a Comment