-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprint.html
More file actions
763 lines (729 loc) · 30.6 KB
/
print.html
File metadata and controls
763 lines (729 loc) · 30.6 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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>The 3 Stages of Docker Debugging</title>
<link rel="icon" type="image/x-icon" href="mc2/images/favicon.ico">
<link rel="stylesheet" href="mc2/styles/print.css">
<link rel="stylesheet" href="mc2/styles/print-code.css">
</head>
<body>
<div id="bodycontainer">
<div id="frontpage">
<h1>The 3 Stages of Docker Debugging</h1>
<div class="splash"></div>
<img class="logo" src="mc2/images/edument_logo_blue.svg">
</div>
<div id="footer">
<span id="delivery"></span>
<span id="copyright">© Edument 2017</span>
</div>
<div id="overview">
<h2>Course overview</h2>
<div class="overviewlist"><div class="detailedoverview"><div><h4><span>1.</span> Introduction</h4><ol><li>Who am I</li><li>Containerization</li><li>Docker</li></ol></div><div><h4><span>2.</span> The problem</h4><ol><li>Our use case</li><li>Introducing the problem</li></ol></div></div><div><div><h4><span>3.</span> The three stages</h4><ol><li>Stage 1</li><li>Stage 2</li><li>Stage 3</li></ol></div></div></div>
</div>
<div id="slides">
<div class="chaptercontainer">
<div class="chapterstart">
<span>chapter 1 / 3</span>
<h2>Introduction</h2>
</div>
<div class="chaptersectionlist">
<h3>Sections in this chapter:</h3>
<ul>
<li>1. Who am I</li>
<li>2. Containerization</li>
<li>3. Docker</li>
</ul>
</div>
<div class="chaptersections">
<section class="chaptersection">
<section class="sectionheader">
<div>
<h3><span>1-1.</span> Who am I</h3>
</div>
</section>
<section class="slide" data-pos="1-1-1">
<span class="pos">1-1-1</span>
<div class="slidecontent"><h3 id="stephen-lau">Stephen Lau</h3>
<ul>
<li>Originally from Canada</li>
<li>Moved to Sweden 4.5 years ago</li>
<li>Enjoy travelling</li>
<li>Was commuting to China a couple of years</li>
<li>Like tackling complex problems</li>
</ul>
</div></section><section class="slide" data-pos="1-1-2">
<span class="pos">1-1-2</span>
<div class="slidecontent"><h3 id="history">History</h3>
<ul>
<li>Started out in firmware engineering</li>
<li>Worked on the rendering engine for BlackBerry</li>
<li>Have worked with large companies globally on their cloud computing offerings</li>
<li>Have worked at all levels of the stack</li>
<li>Lately even doing some frontend work</li>
</ul>
</div></section><section class="slide" data-pos="1-1-3">
<span class="pos">1-1-3</span>
<div class="slidecontent"><p><img style="max-width: 50%; border: none; box-shadow: none" src="resources/images/edument-logo.png"></p>
<p>A knowledge based company</p>
<ul>
<li>Courses</li>
<li>Consulting/Mentoring</li>
<li>Project Development</li>
</ul>
</div></section>
</section>
<section class="chaptersection">
<section class="sectionheader">
<div>
<h3><span>1-2.</span> Containerization</h3>
<p>Why Containers?</p>
</p>
</div>
</section>
<section class="slide" data-pos="1-2-1">
<span class="pos">1-2-1</span>
<div class="slidecontent"><h3 id="isolation">Isolation</h3>
<p>A lot of projects need some kind of <strong>isolation</strong>.</p>
<p>This may be from a security perspective, or to avoid
other processes from conflicting on shared infrastructure.</p>
</div></section><section class="slide" data-pos="1-2-2">
<span class="pos">1-2-2</span>
<div class="slidecontent"><h3 id="reproducibility">Reproducibility</h3>
<p>In addition we want to ensure we have <strong>reproducible environments</strong>.</p>
</div></section><section class="slide" data-pos="1-2-3">
<span class="pos">1-2-3</span>
<div class="slidecontent"><h3 id="virtual-machines">Virtual Machines</h3>
<p><img style="max-width: 60%" src="resources/images/VM.png"></p>
</div></section><section class="slide" data-pos="1-2-4">
<span class="pos">1-2-4</span>
<div class="slidecontent"><p>Abstraction of a <strong>physical machine</strong>.</p>
<ul>
<li>Full copy of OS</li>
<li>One or multiple apps</li>
<li>Necessary Binaries + Libraries</li>
<li>Multiple VMs on a single physical machine</li>
</ul>
</div></section><section class="slide" data-pos="1-2-5">
<span class="pos">1-2-5</span>
<div class="slidecontent"><div class="container-fluid">
<div class="row">
<div class="col-6">
<div>Pros:</div>
<ul>
<li>Isolated</li>
<li>Reproducible</li>
</ul>
</div>
<div class="col-6">
<div>Cons:</div>
<ul>
<li>Large sizes</li>
<li>Long startup time</li>
<li>High maintenance burden</li>
</ul>
</div>
</div>
</div></div></section><section class="slide" data-pos="1-2-6">
<span class="pos">1-2-6</span>
<div class="slidecontent"><h3 id="containers">Containers</h3>
<p><img style="max-width: 60%" src="resources/images/Container.png"></p>
</div></section><section class="slide" data-pos="1-2-7">
<span class="pos">1-2-7</span>
<div class="slidecontent"><p>Abstraction at the <strong>app layer</strong>.</p>
<p>Containers share the <strong>OS kernel</strong> and run in <strong>isolated processes</strong>.</p>
</div></section><section class="slide" data-pos="1-2-8">
<span class="pos">1-2-8</span>
<div class="slidecontent"><div class="container-fluid">
<div class="row">
<div class="col-6">
<div>Pros:</div>
<ul>
<li>Relatively Isolated</li>
<li>Reproducible</li>
<li>Lightweight</li>
<li>Low maintenance burden</li>
</ul>
</div>
<div class="col-6">
<div>Cons:</div>
<ul>
<li>Not completely isolated</li>
<li>Security - Kernel vulnerabilities jeopardize other containers</li>
</ul>
</div>
</div>
</div></div></section><section class="slide question" data-pos="1-2-9">
<span class="pos">1-2-9</span>
<div class="slidecontent">
<p>So, should we not use a virtual machine at all then?</p>
</div></section><section class="slide answer" data-pos="1-2-10">
<span class="pos">1-2-10</span>
<div class="slidecontent">
<p>You still might. In fact, it's not entirely uncommon to run one or
several containers <strong>inside a VM</strong>.</p>
</div></section><section class="slide" data-pos="1-2-11">
<span class="pos">1-2-11</span>
<div class="slidecontent"><h3 id="containers-with-vms">Containers with VMs</h3>
<p><img style="max-width: 60%" src="resources/images/containers-vms-together.png"></p>
</div></section><section class="slide" data-pos="1-2-12">
<span class="pos">1-2-12</span>
<div class="slidecontent"><p>A VM and a container simply have <strong>different use-cases</strong>, but they
are not in any way mutually exclusive.</p>
<ul>
<li><div class='small'>For latency-sensitive applications, you might consider running on real hardware.</div></li>
<li><div class='small'>For optimized system load, you might consider a VM.</div></li>
<li><div class='small'>For mixed workloads, you might consider running containers on both.</div></li>
</ul>
</div></section>
</section>
<section class="chaptersection">
<section class="sectionheader">
<div>
<h3><span>1-3.</span> Docker</h3>
</div>
</section>
<section class="slide" data-pos="1-3-1">
<span class="pos">1-3-1</span>
<div class="slidecontent"><p>A lot of projects need some kind of <strong>isolation</strong>. This
may be from a security perspective, or to reliably recreate a certain
environment.</p>
</div></section><section class="slide" data-pos="1-3-2">
<span class="pos">1-3-2</span>
<div class="slidecontent"><p><img src="resources/images/docker.png" alt="docker"></p>
<p>This is where Docker comes in. It allows you to <strong>containerize</strong>
software, installing exactly the things you need, and to reliably
redeploy this container.</p>
</div></section><section class="slide" data-pos="1-3-3">
<span class="pos">1-3-3</span>
<div class="slidecontent"><h2 id="docker-vocabulary">Docker Vocabulary</h2>
<ul>
<li>Docker Engine CE</li>
<li>Docker Engine EE</li>
<li>Docker Machine</li>
<li>Docker Registry</li>
<li>Docker Hub/Store</li>
<li>Docker Compose</li>
<li>Docker Swarm</li>
</ul>
</div></section><section class="slide" data-pos="1-3-4">
<span class="pos">1-3-4</span>
<div class="slidecontent"><p><strong>Docker Engine CE</strong>/<strong>Docker Engine EE</strong></p>
<p>Docker Engine is what we usually refer to when we say docker.
It's comprised of two parts:</p>
<ul>
<li>Docker Daemon</li>
<li>Docker CLI</li>
</ul>
</div></section><section class="slide" data-pos="1-3-5">
<span class="pos">1-3-5</span>
<div class="slidecontent"><p><strong>Docker Machine</strong></p>
<p>Allows <strong>installation and control</strong> of docker engine on virtual hosts.</p>
</div></section><section class="slide" data-pos="1-3-6">
<span class="pos">1-3-6</span>
<div class="slidecontent"><p><strong>Docker Registry</strong></p>
<p>An open source server side application that allows <strong>storage</strong> and
<strong>distribution</strong> of docker images.</p>
</div></section><section class="slide" data-pos="1-3-7">
<span class="pos">1-3-7</span>
<div class="slidecontent"><p><strong>Docker Hub/Store</strong></p>
<p>Previously known as Docker Hub, Docker Store offers a way to get
various images some of which are "certified".</p>
</div></section><section class="slide" data-pos="1-3-8">
<span class="pos">1-3-8</span>
<div class="slidecontent"><p><strong>Docker Compose</strong></p>
<p>A handy tool for running multiple related docker images.</p>
</div></section><section class="slide" data-pos="1-3-9">
<span class="pos">1-3-9</span>
<div class="slidecontent"><p><strong>Docker Swarm</strong></p>
<p>Allows for management of a cluster of docker hosts to schedule
and deploy multiple docker images across the cluster.</p>
</div></section><section class="slide" data-pos="1-3-10">
<span class="pos">1-3-10</span>
<div class="slidecontent"><p>In the upcoming sections, we'll explore how to <strong>create containers</strong>
and work with <strong>base images</strong>.</p>
</div></section><section class="slide" data-pos="1-3-11">
<span class="pos">1-3-11</span>
<div class="slidecontent"><p>Today we'll be experimenting with <strong>Docker Engine</strong> and <strong>Docker Compose</strong>.</p>
</div></section>
</section>
</div>
</div>
<div class="chaptercontainer">
<div class="chapterstart">
<span>chapter 2 / 3</span>
<h2>The problem</h2>
</div>
<div class="chaptersectionlist">
<h3>Sections in this chapter:</h3>
<ul>
<li>1. Our use case</li>
<li>2. Introducing the problem</li>
</ul>
</div>
<div class="chaptersections">
<section class="chaptersection">
<section class="sectionheader">
<div>
<h3><span>2-1.</span> Our use case</h3>
<p>Guess a UUID</p>
</p>
</div>
</section>
<section class="slide" data-pos="2-1-1">
<span class="pos">2-1-1</span>
<div class="slidecontent"><h3 id="a-simple-game-">A simple game*</h3>
<p><img style="max-width: 70%" src="resources/images/guess-a-uuid.png"></p>
<p><strong>* some cheating required...</strong></p>
</div></section><section class="slide" data-pos="2-1-2">
<span class="pos">2-1-2</span>
<div class="slidecontent"><h3 id="generating-the-uuid-">Generating the uuid:</h3>
<p><pre><code><span class="hljs-keyword">import</span> uuid <span class="hljs-keyword">from</span> <span class="hljs-string">'uuid/v4'</span>;
<span class="hljs-keyword">let</span> uuidToGuess;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">resetUuid</span>(<span class="hljs-params"></span>) </span>{
uuidToGuess = uuid();
}
resetUuid();</code></pre></p>
</div></section><section class="slide" data-pos="2-1-3">
<span class="pos">2-1-3</span>
<div class="slidecontent"><h3 id="serving-a-simple-page-">Serving a simple page:</h3>
<p><pre><code>app.get(<span class="hljs-string">'/'</span>, (req, res) => {
res.status(<span class="hljs-number">200</span>).send(<span class="hljs-string">'<h1>Guess a uuid!</h1><br>'</span> +
<span class="hljs-string">'Guess here: /guess/:uuid-to-guess<br>'</span> +
<span class="hljs-string">'Reset Game Here: /reset'</span>);
});</code></pre></p>
</div></section><section class="slide" data-pos="2-1-4">
<span class="pos">2-1-4</span>
<div class="slidecontent"><h3 id="the-routes-">The routes:</h3>
<p><pre><code>app.get(<span class="hljs-string">'/guess/:uuid'</span>, (req, res) => {
res.status(<span class="hljs-number">200</span>).json({<span class="hljs-string">'correct'</span>: uuidToGuess === req.params.uuid});
});
app.get(<span class="hljs-string">'/reset'</span>, (req, res) => {
resetUuid();
res.status(<span class="hljs-number">200</span>).send(<span class="hljs-string">'uuid to guess is now reset!'</span>);
});</code></pre></p>
</div></section><section class="slide" data-pos="2-1-5">
<span class="pos">2-1-5</span>
<div class="slidecontent"><h3 id="the-docker-file-">The docker file:</h3>
<p><pre><code><span class="hljs-keyword">FROM</span> node:<span class="hljs-number">8</span>
<span class="hljs-keyword">WORKDIR</span><span class="bash"> /work
</span><span class="hljs-keyword">COPY</span><span class="bash"> ./ /work/
</span><span class="hljs-comment">#RUN npm install</span>
<span class="hljs-comment">#RUN npm run build</span>
<span class="hljs-keyword">EXPOSE</span> <span class="hljs-number">8080</span>
<span class="hljs-keyword">CMD</span><span class="bash"> [<span class="hljs-string">"node"</span>, <span class="hljs-string">"server-build.js"</span>]</span></code></pre></p>
</div></section>
</section>
<section class="chaptersection">
<section class="sectionheader">
<div>
<h3><span>2-2.</span> Introducing the problem</h3>
<p>Debugging outside of Docker</p>
</p>
</div>
</section>
<section class="slide" data-pos="2-2-1">
<span class="pos">2-2-1</span>
<div class="slidecontent"><h3 id="debug-in-ide">Debug in IDE</h3>
<ul>
<li>Run app as per normal</li>
<li>Set breakpoints</li>
<li>Dockerize app</li>
<li>Run Docker container</li>
<li><strong>Cross fingers!</strong></li>
</ul>
</div></section><section class="slide" data-pos="2-2-2">
<span class="pos">2-2-2</span>
<div class="slidecontent"><h3 id="configure-debugger-">Configure debugger:</h3>
<p><img style="max-width: 70%" src="resources/images/debugger-setup.png"></p>
</div></section><section class="slide" data-pos="2-2-3">
<span class="pos">2-2-3</span>
<div class="slidecontent"><h3 id="set-breakpoint-">Set breakpoint:</h3>
<p><img style="max-width: 70%" src="resources/images/breakpoint.png"></p>
</div></section><section class="slide" data-pos="2-2-4">
<span class="pos">2-2-4</span>
<div class="slidecontent"><h3 id="setup-source-maps-">Setup source maps:</h3>
<p><pre><code> <span class="hljs-string">"scripts"</span>: {
<span class="hljs-string">"test"</span>: <span class="hljs-string">"echo \"Error: no test specified\" && exit 1"</span>,
<span class="hljs-string">"serve"</span>: <span class="hljs-string">"babel-node server.js"</span>,
<span class="hljs-string">"build"</span>: <span class="hljs-string">"babel server.js -o server-build.js --source-maps inline"</span>
},
</code></pre></p>
</div></section><section class="slide" data-pos="2-2-5">
<span class="pos">2-2-5</span>
<div class="slidecontent"><h3 id="debugger-configured-with-source-maps">Debugger configured with source maps</h3>
<p><img style="max-width: 70%" src="resources/images/debugger-setup-sourcemap.png"></p>
</div></section><section class="slide" data-pos="2-2-6">
<span class="pos">2-2-6</span>
<div class="slidecontent"><h3 id="demo">Demo</h3>
<p><strong>Trying the game</strong></p>
</div></section><section class="slide" data-pos="2-2-7">
<span class="pos">2-2-7</span>
<div class="slidecontent"><h3 id="building-the-docker-image">Building the Docker image</h3>
<p><pre><code>$ docker build . -t game:s0
</code></pre></p>
</div></section><section class="slide" data-pos="2-2-8">
<span class="pos">2-2-8</span>
<div class="slidecontent"><h3 id="running-the-docker-image">Running the Docker image</h3>
<p><pre><code>$ docker run -p8080:8080 game:s0
</code></pre></p>
</div></section><section class="slide" data-pos="2-2-9">
<span class="pos">2-2-9</span>
<div class="slidecontent"><h3 id="running-detached">Running Detached</h3>
<p><pre><code>$ docker run -d -p8080:8080 game:s0
</code></pre></p>
</div></section><section class="slide" data-pos="2-2-10">
<span class="pos">2-2-10</span>
<div class="slidecontent"><h3 id="demo">Demo</h3>
<p><strong>Our isolated game</strong></p>
</div></section><section class="slide" data-pos="2-2-11">
<span class="pos">2-2-11</span>
<div class="slidecontent"><p><strong>Currently we have no way to debug our game while running in docker.</strong></p>
</div></section>
</section>
</div>
</div>
<div class="chaptercontainer">
<div class="chapterstart">
<span>chapter 3 / 3</span>
<h2>The three stages</h2>
</div>
<div class="chaptersectionlist">
<h3>Sections in this chapter:</h3>
<ul>
<li>1. Stage 1</li>
<li>2. Stage 2</li>
<li>3. Stage 3</li>
</ul>
</div>
<div class="chaptersections">
<section class="chaptersection">
<section class="sectionheader">
<div>
<h3><span>3-1.</span> Stage 1</h3>
<p>Docker logging</p>
</p>
</div>
</section>
<section class="slide" data-pos="3-1-1">
<span class="pos">3-1-1</span>
<div class="slidecontent"><h3 id="modifying-our-source">Modifying our source</h3>
<p><pre><code><span class="hljs-keyword">let</span> uuidToGuess;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">resetUuid</span>(<span class="hljs-params"></span>) </span>{
uuidToGuess = uuid();
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">`uuid to guess: <span class="hljs-subst">${uuidToGuess}</span>`</span>);
}</code></pre></p>
</div></section><section class="slide" data-pos="3-1-2">
<span class="pos">3-1-2</span>
<div class="slidecontent"><h3 id="building-our-image">Building our image</h3>
<p><pre><code>$ docker build . -t game:s1
Sending build context to Docker daemon 12.85MB
Step 1/7 : FROM node:8
<span class="hljs-comment">#... truncated</span>
Removing intermediate container 0c8b21542167
Successfully built 455d9c957892
Successfully tagged game:s1
</code></pre></p>
</div></section><section class="slide" data-pos="3-1-3">
<span class="pos">3-1-3</span>
<div class="slidecontent"><h3 id="running-our-container">Running our container</h3>
<p><pre><code>$ docker run -d -p8080:8080 game:s1
11e228cfbf32c68a20735bb4d719b956591b6e7bb77b78b212dff33f619191de
</code></pre></p>
</div></section><section class="slide" data-pos="3-1-4">
<span class="pos">3-1-4</span>
<div class="slidecontent"><h3 id="getting-our-logs">Getting our logs</h3>
<p><pre><code>$ docker logs 11e228c
uuid to guess: 55c8f651-0181-40f7-b6a8-07dea150c86f
Server running on port 8080
</code></pre></p>
</div></section><section class="slide" data-pos="3-1-5">
<span class="pos">3-1-5</span>
<div class="slidecontent"><h3 id="demo">Demo</h3>
<p><strong>Winning with logs</strong></p>
</div></section><section class="slide" data-pos="3-1-6">
<span class="pos">3-1-6</span>
<div class="slidecontent"><h3 id="pros-">Pros:</h3>
<ul>
<li>Fine for simple examples</li>
<li>Simple to work with</li>
<li>Can go back and audit logs</li>
</ul>
</div></section><section class="slide" data-pos="3-1-7">
<span class="pos">3-1-7</span>
<div class="slidecontent"><h3 id="cons-">Cons:</h3>
<ul>
<li>Not really scalable</li>
<li>We may put logging in the wrong place</li>
<li>Can lose context (if adding logs)</li>
</ul>
</div></section><section class="slide" data-pos="3-1-8">
<span class="pos">3-1-8</span>
<div class="slidecontent"><p><strong>Disclaimer</strong></p>
<p>Logging is a powerful tool, when used correctly.</p>
</div></section>
</section>
<section class="chaptersection">
<section class="sectionheader">
<div>
<h3><span>3-2.</span> Stage 2</h3>
<p>Open a port</p>
</p>
</div>
</section>
<section class="slide" data-pos="3-2-1">
<span class="pos">3-2-1</span>
<div class="slidecontent"><h3 id="node-js-remote-debugger">Node.js Remote Debugger</h3>
<ul>
<li>Allows debugging of remote processes</li>
<li>Connects via v8-inspector protocol<strong>*</strong></li>
</ul>
<p><strong> * Versions 7.7 and older use debugger protocol</strong></p>
</div></section><section class="slide" data-pos="3-2-2">
<span class="pos">3-2-2</span>
<div class="slidecontent"><h3 id="configuring-to-run-inspection-mode">Configuring to run inspection mode</h3>
<p><img style="max-width: 70%" src="resources/images/run-inspect-setup.png"></p>
</div></section><section class="slide" data-pos="3-2-3">
<span class="pos">3-2-3</span>
<div class="slidecontent"><h3 id="configuring-chromium-debugger">Configuring chromium debugger</h3>
<p><img style="max-width: 70%" src="resources/images/inspector-setup.png"></p>
</div></section><section class="slide" data-pos="3-2-4">
<span class="pos">3-2-4</span>
<div class="slidecontent"><h3 id="demo">Demo</h3>
<p><strong><em>"Remote"</em> debugging locally</strong></p>
</div></section><section class="slide" data-pos="3-2-5">
<span class="pos">3-2-5</span>
<div class="slidecontent"><h3 id="wrapping-in-docker">Wrapping in docker</h3>
<p><pre><code><span class="hljs-keyword">FROM</span> node:<span class="hljs-number">8</span>
<span class="hljs-keyword">WORKDIR</span><span class="bash"> /work
</span><span class="hljs-keyword">COPY</span><span class="bash"> ./ /work/
</span><span class="hljs-comment">#RUN npm install</span>
<span class="hljs-comment">#RUN npm run build</span>
<span class="hljs-keyword">EXPOSE</span> <span class="hljs-number">8080</span>
<span class="hljs-keyword">EXPOSE</span> <span class="hljs-number">9229</span>
<span class="hljs-keyword">CMD</span><span class="bash"> [<span class="hljs-string">"node"</span>, <span class="hljs-string">"--inspect=0.0.0.0:9229"</span>, <span class="hljs-string">"server-build.js"</span>]</span></code></pre></p>
</div></section><section class="slide" data-pos="3-2-6">
<span class="pos">3-2-6</span>
<div class="slidecontent"><h3 id="running-our-container">Running our container</h3>
<p><pre><code>$ docker run -d -p8080:8080 -p9229:9229 game:s2
11e228cfbf32c68a20735bb4d719b956591b6e7bb77b78b212dff33f619191de
</code></pre></p>
</div></section><section class="slide" data-pos="3-2-7">
<span class="pos">3-2-7</span>
<div class="slidecontent"><h3 id="problems">Problems</h3>
<ul>
<li>Port is always open</li>
<li>Container is in debug mode</li>
<li>Run command is getting long</li>
</ul>
</div></section><section class="slide" data-pos="3-2-8">
<span class="pos">3-2-8</span>
<div class="slidecontent"><h3 id="solution">Solution</h3>
<p><strong>Docker Compose</strong></p>
</div></section><section class="slide" data-pos="3-2-9">
<span class="pos">3-2-9</span>
<div class="slidecontent"><p>docker-compose.yml
<pre><code><span class="hljs-attr">version:</span> <span class="hljs-string">'2'</span>
<span class="hljs-attr">services:</span>
<span class="hljs-attr"> deployment:</span>
<span class="hljs-attr"> build:</span> <span class="hljs-string">./</span>
<span class="hljs-attr"> image:</span> <span class="hljs-string">game-deployment</span>
<span class="hljs-attr"> ports:</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">"8080:8080"</span>
<span class="hljs-attr"> debug:</span>
<span class="hljs-attr"> build:</span>
<span class="hljs-attr"> context:</span> <span class="hljs-string">./</span>
<span class="hljs-attr"> dockerfile:</span> <span class="hljs-string">Dockerfile.debug</span>
<span class="hljs-attr"> image:</span> <span class="hljs-string">game-debug</span>
<span class="hljs-attr"> ports:</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">"8080:8080"</span>
<span class="hljs-bullet"> -</span> <span class="hljs-string">"9229:9229"</span></code></pre></p>
</div></section><section class="slide" data-pos="3-2-10">
<span class="pos">3-2-10</span>
<div class="slidecontent"><h3 id="using-docker-compose">Using docker compose</h3>
<p><pre><code>$ docker-compose build debug
$ docker-compose up -d debug
$ docker-compose down
</code></pre></p>
</div></section><section class="slide" data-pos="3-2-11">
<span class="pos">3-2-11</span>
<div class="slidecontent"><h3 id="demo">Demo</h3>
<p><strong>Running with docker-compose</strong></p>
</div></section><section class="slide" data-pos="3-2-12">
<span class="pos">3-2-12</span>
<div class="slidecontent"><h3 id="pros">Pros</h3>
<ul>
<li>Can connect a debugger into Docker container</li>
</ul>
</div></section><section class="slide" data-pos="3-2-13">
<span class="pos">3-2-13</span>
<div class="slidecontent"><h3 id="cons">Cons</h3>
<ul>
<li>Security - debug port left open</li>
<li>Lose context (if not using debug container)</li>
<li>Have to maintain two different docker files</li>
</ul>
</div></section>
</section>
<section class="chaptersection">
<section class="sectionheader">
<div>
<h3><span>3-3.</span> Stage 3</h3>
<p>Docker networking</p>
</p>
</div>
</section>
<section class="slide" data-pos="3-3-1">
<span class="pos">3-3-1</span>
<div class="slidecontent"><h3 id="changing-node-to-debug-mode">Changing node to debug mode</h3>
<p><pre><code>$ node server-build.js
Server running on port 8080
</code></pre></p>
<p><pre><code>$ ps -C node
PID TTY TIME CMD
7433 pts/15 00:00:00 node
$ <span class="hljs-built_in">kill</span> -s USR1 7433
</code></pre></p>
<p>Result:
<pre><code>$ node server-build.js
Server running on port 8080
Starting debugger agent.
Debugger listening on 127.0.0.1:5858
</code></pre></p>
</div></section><section class="slide" data-pos="3-3-2">
<span class="pos">3-3-2</span>
<div class="slidecontent"><h3 id="sending-a-signal-into-docker">Sending a signal into Docker</h3>
<p><pre><code>$ docker run -d game:s0
c6985986393a2cee97bbb53de8a172176d4662edf9bd2472be61eaf656b2a2f7
$ docker logs c6985
Server running on port 8080
$ docker <span class="hljs-built_in">kill</span> -s SIGUSR1 c6985
c6985
$ docker logs c6985
Server running on port 8080
Debugger listening on ws://127.0.0.1:9229/619d5499-4c9d...
For <span class="hljs-built_in">help</span> see https://nodejs.org/en/docs/inspector
</code></pre></p>
</div></section><section class="slide" data-pos="3-3-3">
<span class="pos">3-3-3</span>
<div class="slidecontent"><h3 id="demo">Demo</h3>
<p><strong>Signaling our node app</strong></p>
</div></section><section class="slide" data-pos="3-3-4">
<span class="pos">3-3-4</span>
<div class="slidecontent"><h3 id="the-situation">The situation</h3>
<p><img style="max-width: 50%" src="resources/images/game-container-situation.png"></p>
</div></section><section class="slide" data-pos="3-3-5">
<span class="pos">3-3-5</span>
<div class="slidecontent"><h3 id="problems">Problems</h3>
<ul>
<li>Container <strong>may</strong> be in an isolated network</li>
<li>No ports are open</li>
<li>Debugger is listening on 127.0.0.1</li>
</ul>
</div></section><section class="slide" data-pos="3-3-6">
<span class="pos">3-3-6</span>
<div class="slidecontent"><h3 id="our-goals">Our Goals</h3>
<ul>
<li>Connect to the container (even if isolated)</li>
<li>Don't leave any ports open</li>
<li>Pretend to be localhost</li>
</ul>
</div></section><section class="slide" data-pos="3-3-7">
<span class="pos">3-3-7</span>
<div class="slidecontent"><h3 id="the-plan">The plan</h3>
<p><img style="max-width: 70%" src="resources/images/the-plan.png"></p>
</div></section><section class="slide" data-pos="3-3-8">
<span class="pos">3-3-8</span>
<div class="slidecontent"><ol>
<li>Send SIGUSR1 to switch to debug mode.</li>
<li>Connect a "sidecar" container to the same network interface.</li>
<li>Connect a forwarding container to the same network as "sidecar".</li>
<li>Connect to the forwarding container via our debugger.</li>
</ol>
</div></section><section class="slide" data-pos="3-3-9">
<span class="pos">3-3-9</span>
<div class="slidecontent"><h3 id="socat">Socat</h3>
<blockquote>
<p>Socat is a command line based utility that establishes two
bidirectional byte streams and transfers data between them.</p>
</blockquote>
</div></section><section class="slide" data-pos="3-3-10">
<span class="pos">3-3-10</span>
<div class="slidecontent"><h3 id="connecting-the-sidecar">Connecting the sidecar</h3>
<p><pre><code>docker run -d --name socat-attach --network=container:<span class="hljs-variable">${TARGET_CONTAINER}</span> \
socat-image socat TCP-LISTEN:<span class="hljs-variable">${TEMP_PORT}</span>,fork TCP:127.0.0.1:9229
</code></pre>
<br></p>
<ul>
<li><code>${TARGET_CONTAINER}</code> is the container ID</li>
<li><code>${TEMP_PORT}</code> is a port to connect sidecar to forwarding container</li>
</ul>
</div></section><section class="slide" data-pos="3-3-11">
<span class="pos">3-3-11</span>
<div class="slidecontent"><h3 id="connecting-the-forwarding-container">Connecting the forwarding container</h3>
<p><pre><code>docker run -d -p 9229:9229 --name socat-fw socat-image socat \
TCP-LISTEN:9229,fork TCP:<span class="hljs-variable">${TARGET_IP}</span>:<span class="hljs-variable">${TEMP_PORT}</span>
</code></pre>
<br></p>
<ul>
<li><code>${TARGET_IP}</code> is the targets IP</li>
<li><code>${TEMP_PORT}</code> is a port to connect sidecar to forwarding container</li>
</ul>
</div></section><section class="slide" data-pos="3-3-12">
<span class="pos">3-3-12</span>
<div class="slidecontent"><h3 id="finding-the-ip-address">Finding the IP address</h3>
<pre><code>$ docker inspect ${TARGET_CONTAINER}
#...
"Networks": {
"bridge": {
#...
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
</code></pre></div></section><section class="slide" data-pos="3-3-13">
<span class="pos">3-3-13</span>
<div class="slidecontent"><h3 id="demo">Demo</h3>
<p><strong>Putting it all together!</strong></p>
</div></section><section class="slide" data-pos="3-3-14">
<span class="pos">3-3-14</span>
<div class="slidecontent"><p>Pros:</p>
<ul>
<li>No Ports left open</li>
<li>No context lost</li>
<li>One docker file to maintain</li>
</ul>
</div></section><section class="slide" data-pos="3-3-15">
<span class="pos">3-3-15</span>
<div class="slidecontent"><p>Cons:</p>
<ul>
<li>Can't audit logs</li>
<li>App is left in debug mode</li>
</ul>
</div></section><section class="slide" data-pos="3-3-16">
<span class="pos">3-3-16</span>
<div class="slidecontent"><h3 id="recommendations-">Recommendations:</h3>
<ul>
<li>Use logging to create audit logs</li>
<li>Debug using Docker networking</li>
<li>Restart/Kill containers after debugging</li>
</ul>
</div></section>
</section>
</div>
</div>
</div>
<div id="indexes">
</div>
</div>
<script type="text/javascript" src="/reload/reload.js"></script>
</body>
</html>