forked from Sonal0409/DevOps_ClassNotes
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdockerStack_NOTES
More file actions
166 lines (115 loc) · 2.97 KB
/
dockerStack_NOTES
File metadata and controls
166 lines (115 loc) · 2.97 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
Docker Stack
This is used for creating a muiltcontainer architecture using docker compose and deploy it in the swarm cluster.
Docker compose + swarm = docker stack.
Commands
1.To see list of stack
# docker stack ls
2.To create a stck
# docker stack deploy -c stack_filename/docker_composefilename stackname
3.To see list of nodes where the stack service is running
# docker stack ps stackname
4.To see list of services in docker stack
# docker stack service stack_name
5.To delete a stck
# docker stack rm stack_name
Example:
Create a directory==>goinside the directory
Create a yml file ==> vim stack1.yml
---
version: 3
services:
mydb:
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: edureka
myworsdpress:
image: wordpress
ports:
-5050:80
deploy:
replicas: 3
...
To deploy the stack service
# docker stack deploy -c stack1.yml wordpress
Here -c : allows you to create docker compose file with any name
3.To see where the stack replicas are running
# docker stack ps wordpress
3 replicas of wordpress and 1 mysql replica will be created
4.To remove the stack
# docker stack rm wordpress
Example2:
Starting a jenkins linked with 2 tomcat servers, creating a stack file and adding details like no: of replicas and which service to run on which node
# vim stack2.yml
---
version: 3
services:
jenkins:
image: jenkins
ports:
-5050:8080
deploy:
replicas: 2
placement:
constraints:
-node.hostname == Manager
qaserver:
image: tomcat
ports:
-6060:8080
deploy:
replicas: 2
placement:
constraints:
-node.hostname == Worker1
prodserver:
image: tomcat
ports:
-7070:8080
deploy:
replicas: 3
placement:
constraints:
-node.hostname == Worker2
…
:wq!
# docker stack deploy -c stack2.yml stack-ci-cd
# docker stack ps stackci-cd
So all the replicas will be created will be running on thesre respective manager, worker 1 and worker 2 node as mentioned in stack file
Here under constraints we have give 1 node, but if you want we can give more than 1 node also, so if one node is not available then the service will start running on another node.
If in conatraint you have given only 1 node, then if the node is out of resources or is down, then the services will wait until that node comes alive again.
Example2: Advance:
Create a docker stack file to setup the selenium testing environment and also put an upper limit on the h/w allocation
---
version: '3'
services:
hub:
image: selenium/hub
ports:
-4444:4444
deploy:
replicas: 1
resources:
limits:
cpus: "0.1"
memory: "200M"
chrome:
image: selenium/node-chrome-debug
ports:
-5901:5900
deploy:
replicas: 2
resources:
limits:
cpus: "0.01"
memory: "100M"
firefox:
image: selenium/node-firefox-debug
ports:
-5901:5900
deploy:
replicas: 1
…
2.To deploy the services from above stack file:
# docker stack deploy -c stack3.yml selenium
3.View the services
# docker stack ps selenium