-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathday4.txt
393 lines (239 loc) · 9.33 KB
/
day4.txt
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
What is a Docker Swarm?
=========================
A Docker Swarm is a group of either physical or virtual machines that are running the Docker application and that have been configured to join together in a cluster. Once a group of machines have been clustered together, you can still run the Docker commands that you're used to, but they will now be carried out by the machines in your cluster. The activities of the cluster are controlled by a swarm manager, and machines that have joined the cluster are referred to as nodes.
Docker swarm is a container orchestration tool, meaning that it allows the user to manage multiple containers deployed across multiple host machines..
One of the key benefits associated with the operation of a docker swarm is the high level of availability offered for applications. In a docker swarm, there are typically several worker nodes and at least one manager node that is responsible for handling the worker nodes' resources efficiently and ensuring that the cluster operates efficiently.
To create Docker Swarm
========================
docker swarm init --advertise-addr=192.168.0.8
Swarm initialized: current node (ki99an0dnuhzeosjz0nve6wl1) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-03r7a85clnd551byp3hnpks4g0qp834kl0lrzztzctdojqeo2x8jrhhi3ghfvj2prnn4pihxp5q 192.168.0.8:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Usage: docker node COMMAND
Manage Swarm nodes
Commands:
demote Demote one or more nodes from manager in the swarm
inspect Display detailed information on one or more nodes
ls List nodes in the swarm
promote Promote one or more nodes to manager in the swarm
ps List tasks running on one or more nodes, defaults to current node
rm Remove one or more nodes from the swarm
update Update a node
Usage: docker service COMMAND
Manage services
Commands:
create Create a new service
inspect Display detailed information on one or more services
logs Fetch the logs of a service or task
ls List services
ps List the tasks of one or more services
rm Remove one or more services
rollback Revert changes to a service's configuration
scale Scale one or multiple replicated services
update Update a service
To create 3 nginx containers
===============================
docker run --name a-nginx -p 1111:80 -d nginx
docker run --name b-nginx -p 2222:80 -d nginx
docker run --name c-nginx -p 3333:80 -d nginx
create p-nginx-service
=======================
docker service create --name p-nginx --replicas 3 --publish 1111:80 nginx
docker service create --name p-cafe --replicas 10 --publish 4444:80 pradeepch82/pradeep-cafe:1.1
docker service create --name p-tea --replicas 10 --publish 3333:80 pradeepch82/tea:1.1
docker service update --replicas 10 p-tea
docker service update --replicas 5 p-tea
docker service update --image pradeepch82/tea:1.2 p-tea
docker service update --image pradeepch82/tea:1.3 p-tea
docker service update --image pradeepch82/tea:1.4 p-tea
docker service update --replicas=5 --image pradeepch82/tea:1.4 p-tea
docker service scale p-tea=12 p-coffee=5 p-lunch=6
docker service update --image pradeepch82/tea:1.3 --publish-add published=5555,target=80 p-tea
docker service update --image pradeepch82/tea:1.3 --publish-add published=1111,target=80 p-tea
docker service update --image pradeepch82/tea:1.3 --publish-rm p-tea
Day3
====
Docker Stack
=================
Usage: docker stack [OPTIONS] COMMAND
Manage Docker stacks
Options:
--kubeconfig string
Kubernetes config file
--orchestrator string
Orchestrator to use
(swarm|kubernetes|all)
Commands:
deploy Deploy a new stack or update an existing stack
ls List stacks
ps List the tasks in the stack
rm Remove one or more stacks
services List the services in the stack
Creating the wp-mysql-stack
============================
docker-compose.yml
=====================
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
==========================================================================
docker stack deploy --compose-file docker-compose.yml wp-mysql-stack
docker stack ls
docker stack ps wp-mysql-stack
docker stack services wp-mysql-stack
docker stack rm wp-mysql-stack
docker-compose.yml
===================
version: '3.3'
services:
database:
image: pradeepch82/ems-mysql:1.1
volumes:
- db_data:/var/lib/mysql
restart: always
ems-spring-boot:
depends_on:
- database
image: pradeepch82/pvc-spring-boot-ems:1.2
ports:
- "1212:8080"
restart: always
volumes:
db_data: {}
docker stack deploy --compose-file docker-compose.yml pvc-springboot-mysql
docker-compose.yml
===================
version: '3.3'
services:
database:
image: pradeepch82/ems-mysql:1.1
deploy:
replicas: 3
volumes:
- db_data:/var/lib/mysql
restart: always
networks:
- backendNetwork
- frontendNetwork
ems-spring-boot:
depends_on:
- database
image: pradeepch82/pvc-spring-boot-ems:1.2
deploy:
replicas: 1
ports:
- "1212:8080"
restart: always
networks:
- frontendNetwork
volumes:
db_data: {}
networks:
backendNetwork:
frontendNetwork:
docker stack deploy --compose-file docker-compose.yml pvc-springboot-mysql
============================================
docker-compse with swarm
============================
version: '3'
services:
database:
image: pradeepch82/ems-mysql:1.1
deploy:
replicas: 2
container_name: database
volumes:
- dockerAngularSpringDatabaseData:/var/lib/mysql
networks:
- backendNetwork
spring-boot-ems:
image: pradeepch82/pvc-spring-boot-ems:1.2
deploy:
replicas: 3
ports:
- 1212:8080
depends_on:
- database
networks:
- backendNetwork
- frontendNetwork
ems-angular-app:
image: pradeepch82/ems-angular-app:1.2
deploy:
replicas: 3
ports:
- 4200:80
depends_on:
- spring-boot-ems
networks:
- frontendNetwork
volumes:
dockerAngularSpringDatabaseData:
networks:
backendNetwork:
frontendNetwork:
docker stack deploy --compose-file docker-compose.yml angular-spring-mysql-stack
Day4
=====================================================================
To start a single container from image : docker run
To start a multiple container in one command : docker-compose up -d
To start a multiple containers via service in swarm : docker service create
To start a multiple services in swarm : docker stack deploy
docker service update --replicas 5 pvc-springboot-mysql_database
docker service scale pvc-springboot-mysql_ems-spring-boot=3 pvc-springboot-mysql_database=7
docker events --filter 'event=stop'
docker events --filter 'event=start'
docker events --filter 'event=create'
docker volume : used to share the data among containers
==============
docker volume ls
docker volume create p-mysql-volume
docker run --name a-mysql -v p-mysql-volume:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_DATABASE=company -d mysql:5.7
docker exec -it a-mysql bash
mysql -uroot -padmin
use company
create table employee(id int primary key,name text);
insert into employee values(101,'Pradeep');
insert into employee values(102,'Sachin');
insert into employee values(103,'Sunil');
select * from employee;
exit
exit
docker stop a-mysql
docker rm a-mysql;
docker run --name b-mysql -v p-mysql-volume:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=admin -e MYSQL_DATABASE=company -d mysql:5.7
docker exec -it b-mysql bash
mysql -uroot -padmin
use company
select * from employee;
docker history pradeepch82/ems-mysql:1.1
docker volume create pvc-vol
docker service create --name p-nginx --mount type=volume,source=pvc-vol,target=/usr/share/nginx/html --replicas 3 -p 2222:80 nginx
Docker Swarm Volumes.
=========================
Swarm might not look as mature as Kubernetes:
It only comes with one type of volume natively, which is a volume shared between the container and its Docker host. This might come in handy for testing a deployment locally, but it won't do the job on a distributed cluster.