How To Create And Manage Docker Stack
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed docker service.
https://cloudaffaire.com/how-to-create-and-manage-docker-service/
In this blog post, we will discuss how to create and manage docker stack. We will also deploy a docker stack in our existing docker swarm cluster.
Prerequisite for this demo:
- Docker swarm cluster initiated and configured
What is a docker stack?
A stack is a group of interrelated services that share dependencies and can be orchestrated and scaled together. A single stack is capable of defining and coordinating the functionality of an entire application. A stack consists of multiple docker services and is deployed using a docker-compose file. In the last blog post, we have deployed a single docker service in our cluster. In this demo, we will deploy multiple services in the form of docker stack.
How To Create And Manage Docker Stack Demo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
##--------------------- ## Docker: Docker Stack ##--------------------- ## docker stack [OPTIONS] COMMAND ########################### ## Swarm Configuration ## ########################### # hostnames ip os role # --------- ------------ -------- ------------ # system1 192.168.0.10 Centos 7 Manager Node # system2 192.168.0.20 Centos 7 Worker Node One # system3 192.168.0.30 Centos 7 Worker Node Two ######################## ## Stack Deployment ## ######################## ## login to the manager node (192.168.0.10) ## create a docker-compose.yml vi docker-compose.yml ------------------ version: '3' services: web: image: httpd ports: - "8081:80" deploy: replicas: 3 networks: - webnet visualizer: image: dockersamples/visualizer:stable ports: - "8082:8080" volumes: - "/var/run/docker.sock:/var/run/docker.sock" deploy: placement: constraints: [node.role == manager] networks: - webnet networks: webnet: ------------------ :wq ## Deploy a new stack or update an existing stack docker stack deploy -c docker-compose.yml mySTACK ## List stacks docker stack ls ## List the services in the stack docker stack services mySTACK ## List the tasks in the stack docker stack ps mySTACK ## Check the application 192.168.0.10:8082 #since mySTACK_visualizer.1 is running in system1, change as required #make sure port 8082 is open ## Remove one or more stacks docker stack rm mySTACK |
Hope you have enjoyed this article. In the next blog post, we will discuss docker-machine.
To get more details on docker, please refer to Docker documentation.