-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
1972 lines (1603 loc) · 69.2 KB
/
index.html
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
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8" />
<title>How to develop in PHP with Docker and Docker Compose</title>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" />
<meta name="description" content="Development in PHP with Docker" />
<meta name="author" content="Damien Carcel" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui"
/>
</head>
<body>
<div class="reveal">
<div class="slides">
<section id="presentation-title">
<h2>Developing in PHP<br />with Docker and Docker Compose</h2>
<br />
<br />
<div>
<a href="https://github.com/damien-carcel/docker-training" target="_blank"
>https://github.com/damien-carcel/docker-training</a
>
</div>
</section>
<section>
<section>
<h2>About me</h2>
<div class="centered-slide-content two-columns-slide">
<div class="col">
<img alt="pingoo" src="images/pingoo.png" height="200px" />
<br />
<b>Damien Carcel</b>
<br />
<i>Senior Software Engineer</i>
</div>
<div class="col">
<div>
<img class="vertical-align" alt="github" src="images/github-logo.png" height="50px" /> <a
class="vertical-align"
href="https://github.com/damien-carcel"
target="_blank"
>damien-carcel</a
>
</div>
<div>
<img class="vertical-align" alt="mastodon" src="images/mastodon-logo.png" height="50px" /> <a
class="vertical-align"
href="https://social.tchncs.de/@damiencarcel"
target="_blank"
>@[email protected]</a
>
</div>
<div>
<img class="vertical-align" alt="linkedin" src="images/linkedin-logo.png" height="50px" /> <a
class="vertical-align"
href="https://www.linkedin.com/in/damien-carcel/"
target="_blank"
>damien-carcel</a
>
</div>
</div>
</div>
<aside class="notes">Say a few words about Akeneo and the PIM.</aside>
</section>
</section>
<section id="plan">
<section>
<h2>What will we see?</h2>
<div class="centered-slide-content">
<ul class="plan">
<li class="fragment">Presentation of Docker</li>
<li class="fragment">How to use only Docker to create and run a Symfony app</li>
<li class="fragment">How to use Docker Compose to ease our workflow</li>
</ul>
</div>
<aside class="notes">
<p>
We will not use the Symfony CLI tool and its built-in server, only pure PHP, as I want to keep things
simple.
</p>
<p>If enough time, we will se how to run and debug our app in an IDE</p>
</aside>
</section>
<section>
<h2>Practice</h2>
<div class="centered-slide-content">
<ul class="plan">
<li class="practice-goal">Goal</li>
<li class="practice-constraint">Constraints</li>
<li class="practice-success">Success criteria</li>
</ul>
</div>
<aside class="notes"></aside>
</section>
</section>
<section id="presentation">
<section>
<h2>What is (not) Docker?</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment">Docker is not a virtual machine (VM)</li>
</ul>
<br />
<img alt="virtualization.svg" src="images/virtualization.svg" class="fragment" />
</div>
<aside class="notes">A VM runs a full operating system on virtualized hardware.</aside>
</section>
<section>
<h2>Docker is a container orchestrator</h2>
<div class="centered-slide-content">
<img alt="vms_vs_containers.jpg" src="images/vms_vs_containers.jpg" />
<p>Virtual machines vs. containers</p>
</div>
<aside class="notes">
<p>Containers remove the hardware virtualization and the guest OS.</p>
<p>The Docker engine has access to the real hardware and uses the host Linux kernel.</p>
<p>Except on macOS and Windows, as Docker runs in a VM providing a GNU/Linux OS.</p>
</aside>
</section>
<section>
<h2>A few definitions</h2>
<div class="centered-slide-content">
<div class="fragment">
A container is a standard unit of software that packages up code and all its dependencies so the
application runs quickly and reliably from one computing environment to another
</div>
<br />
<br />
<div class="fragment">
A Docker container image is a lightweight, standalone, executable package of software that includes
everything needed to run an application: code, runtime, system tools, system libraries and settings.
</div>
</div>
<aside class="notes">
<p>
Images built from the Dockerfile follow the
<a href="https://opencontainers.org/">Open Container Initiative</a> specifications.
</p>
<p>They are other container systems, like LXC/LXD, not based on the OCI</p>
</aside>
</section>
<section>
<h2>Docker specificity</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment" data-fragment-index="1">Only one process in the container</li>
<li class="fragment" data-fragment-index="2">Dockerfile → Image → Containers</li>
</ul>
<br />
<br />
<pre class="fragment" data-fragment-index="3"><code class="dockerfile">
FROM debian:bookworm-slim
RUN apt-get update && \
apt-get --no-install-recommends --no-install-suggests install php && \
apt-get clean && \
apt-get autoremove --purge
</code></pre>
<legend class="fragment" data-fragment-index="3">A Dockerfile example</legend>
</div>
<aside class="notes">
<p>
Images built from the Dockerfile follow the
<a href="https://opencontainers.org/">Open Container Initiative</a> specifications.
</p>
<p>They are other container systems, like LXD/LXD, not based on the OCI</p>
</aside>
</section>
</section>
<section id="using-docker">
<section>
<h2>How to use Docker</h2>
<div class="centered-slide-content">
<img src="images/docker.png" />
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>How to use Docker</h2>
<div class="centered-slide-content">
<h3>The very basics</h3>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Invoking the Docker CLI</h2>
<div class="centered-slide-content">
<pre class="fragment"><code class="shell">
$ docker
</code></pre>
</div>
<aside class="notes">
<p>Present briefly the various Docker available commands</p>
</aside>
</section>
<section>
<h2>Using Docker - Pulling an image</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment" data-fragment-index="1">Pull the latest Debian “slim” image</li>
<li class="fragment" data-fragment-index="4">List the pulled images</li>
</ul>
<pre class="fragment" data-fragment-index="2"><code class="shell">
$ docker image pull debian:bookworm-slim
</code></pre>
<pre class="fragment" data-fragment-index="3"><code class="shell">
$ docker image pull debian:12-slim
</code></pre>
<pre class="fragment" data-fragment-index="4"><code class="shell">
$ docker image ls
</code></pre>
</div>
<aside class="notes">
<p>Explain "pull" and the tag system</p>
<p>Same ID for same layer => explain the layers</p>
<p>"docker image ls" same thing that "docker images"</p>
<p>Docker image also proposes history and inspect, just show it very briefly</p>
</aside>
</section>
<section>
<h2>Using Docker - Running a container</h2>
<div class="centered-slide-content">
<pre class="fragment" data-fragment-index="1"><code class="shell">
$ docker container run [options] debian:12-slim [command]
</code></pre>
<legend class="fragment" data-fragment-index="1">Basic run example</legend>
</div>
<aside class="notes">
<p>Before image name: options; after image name: command that will run in the container</p>
<p>Try "ls -al" as an example</p>
</aside>
</section>
<section>
<h2>Using Docker - Running a container</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment practice-goal" data-fragment-index="1">Use bash in a container</li>
<br />
<li class="fragment practice-success" data-fragment-index="2">
You need to be able to fully interact<br />
with the console inside your container
</li>
</ul>
<br />
<br />
<div class="fragment" data-fragment-index="3">Tips</div>
<ul class="fragment" data-fragment-index="3">
<li>You need to allocate a pseudo TTY</li>
<li>You need to keep STIN open</li>
</ul>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Running a container</h2>
<div class="centered-slide-content">
<h3>Solution</h3>
<pre class="fragment" data-fragment-index="1"><code class="shell">
$ docker container run -i -t debian:12-slim bash
$ docker container ls -a
$ docker container rm <container name>
</code></pre>
<div class="fragment" data-fragment-index="2">or</div>
<pre class="fragment" data-fragment-index="2"><code class="shell">
$ docker container run -i -t --rm debian:12-slim bash
</code></pre>
</div>
<aside class="notes">
<p>docker container ls -a shows stopped containers</p>
<p>`--rm` is a must-use</p>
</aside>
</section>
<section>
<h2>How to use Docker</h2>
<div class="centered-slide-content">
<h3>Let's go further</h3>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Environment variables</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment">
<code class="shell inline-code">docker container run --env VAR=value</code> can create variables
inside the container
</li>
<br />
<li class="fragment">It will override the value if the variable already exists</li>
</ul>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Environment variables</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment practice-goal" data-fragment-index="1">
Display a host environment variable in a container
</li>
<br />
<li class="fragment practice-constraint" data-fragment-index="2">
Export an environment variable in your terminal
</li>
<li class="fragment practice-constraint" data-fragment-index="3">
The only time you write the value must be for the "export"
</li>
<br />
<li class="fragment practice-success" data-fragment-index="5">
The value is displayed in your terminal
</li>
</ul>
<br />
<br />
<div class="fragment" data-fragment-index="6">Tips</div>
<pre class="fragment" data-fragment-index="6"><code class="shell" data-trim>
$ export MY_VAR="Hello"
$ echo ${VARIABLE_NAME}
</code></pre>
<legend class="fragment" data-fragment-index="6">Display an environment variable</legend>
</div>
<aside class="notes">
<p>Don't make them try a one-line here, too much side effects</p>
</aside>
</section>
<section>
<h2>Using Docker - Environment variables</h2>
<div class="centered-slide-content">
<h3>Solutions</h3>
<pre><code class="shell">
$ export HOST_VAR=Hello
$ docker container run -e CONTAINER_VAR=$HOST_VAR debian:12-slim \
sh -c 'echo $CONTAINER_VAR'
</code></pre>
<div class="fragment" data-fragment-index="1">or</div>
<pre class="fragment" data-fragment-index="1"><code class="shell">
$ export MY_VAR=Hello
$ docker container run -e MY_VAR debian:12-slim sh -c 'echo $MY_VAR'
</code></pre>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Volumes</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment definition" data-fragment-index="1">
Volumes allow to persist data outside the container
</li>
</ul>
<br />
<br />
<pre class="fragment" data-fragment-index="2"><code class="shell">
$ docker volume create my-data
$ docker container run -v my-data:/path-in-container debian:12-slim
</code></pre>
<legend class="fragment" data-fragment-index="2">Create link a Docker volume to your container</legend>
</div>
<aside class="notes">
<p>Show an example by running a MySQL container and inspect the volume to find its path</p>
<p>Most of the major management commands propose `inspect`, use it to show the content of MySQL</p>
<p>Always host path first, then container path</p>
<p>Having the volume allows to bind it to another, new container if the original one was destroyed</p>
</aside>
</section>
<section>
<h2>Using Docker - Bind mount</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment definition" data-fragment-index="1">
Mount a file or directory from the host into the container.
</li>
</ul>
<br />
<br />
<pre class="fragment" data-fragment-index="2"><code class="shell">
$ docker container run \
-v /path-on-host:/path-in-container \
debian:12-slim
</code></pre>
<legend class="fragment" data-fragment-index="2">
Bind mount a folder/file from your host inside the container - old way
</legend>
<br />
<pre class="fragment" data-fragment-index="3"><code class="shell">
$ docker container run \
--mount type=bind,source=/path-on-host,target=/path-in-container \
debian:12-slim
</code></pre>
<legend class="fragment" data-fragment-index="3">
Bind mount a folder/file from your host inside the container - new way
</legend>
</div>
<aside class="notes">
<p>The new mount option works with volumes too, with type=volume</p>
</aside>
</section>
<section>
<h2>Using Docker - Bind mount</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment practice-goal">Bind-mount a directory from your host into the container</li>
<br />
<li class="fragment practice-constraint">
Bind-mount <code class="inline-code">/home/<your login>/training</code> into
<code class="inline-code">/data</code>
</li>
<li class="fragment practice-constraint">
Create a file with <code class="inline-code">echo "This is a test" > /data/test.txt</code>
</li>
<br />
<li class="fragment practice-success">You can open the file and it contains the expected content</li>
</ul>
</div>
<aside class="notes">
<p>We ran the container as "root", so the file was created owned by "root" as well.</p>
</aside>
</section>
<section>
<h2>Using Docker - Bind mount</h2>
<div class="centered-slide-content">
<h3>Solution</h3>
<pre><code class="shell" data-trim data-line-numbers="1-2|1-8|1-12|1-14">
## Create your directory first on the host or it will be owned by root ##
$ mkdir /home/<your login>/training
$ docker container run -i -t --rm \
--mount type=bind,source=/home/<your login>/training,target=/data \
debian:12-slim bash
## Now you are in the container ##
$ echo "This is a test" > /data/test.txt
## CTRL+D to exit ##
$ cat /home/<your login>/training/test.txt
</code></pre>
<ul class="fragment">
<li class="practice-question">Can you spot what's wrong in the result?</li>
</ul>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - User</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment">
<code class="shell inline-code">docker container run --user <username or IDs></code> allows to
specify a user inside the container
</li>
<br />
<li class="fragment">username must correspond to an existing user</li>
<br />
<li class="fragment">User IDs can correspond to nothing</li>
<br />
<li class="fragment">It will override any user already specified as default in the Dockerfile</li>
</ul>
</div>
<aside class="notes">
<p>IMPORTANT: `-u user` → "user" is the user in the container, not on your host</p>
</aside>
</section>
<section>
<h2>Using Docker - User</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment practice-goal">Fix the previous exercise issue</li>
<br />
<li class="fragment practice-constraint">
Again, run a container while bind-mounting,<br />
but this time specify a user
</li>
<li class="fragment practice-constraint">Create a file in <code class="inline-code">/data</code></li>
<br />
<li class="fragment practice-success">
You can edit from your host<br />
the file you created in the container
</li>
</ul>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - User</h2>
<div class="centered-slide-content">
<h3>Solution</h3>
<pre class="fragment"><code class="shell">
$ sudo chown -R $(id -u):$(id -g) /home/<your login>/training
$ docker container run -i -t --rm \
-u $(id -u):$(id -g) \
--mount type=bind,source=/home/<your login>/training,target=/data \
debian:12-slim bash
</code></pre>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - workdir</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment definition">Specifies the working directory of a container</li>
</ul>
<br />
<br />
<pre class="fragment"><code class="shell">
$ docker container run -i -t --rm --workdir /data debian:12-slim bash
</code></pre>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>How to use Docker</h2>
<div class="centered-slide-content">
<h3>Create and serve a Symfony app with Docker only</h3>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Create a Symfony app</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment practice-goal" data-fragment-index="1">
Use the <code class="inline-code">composer:latest</code> Docker image to create a Symfony app
</li>
<br />
<li class="fragment practice-constraint" data-fragment-index="2">
<code class="inline-code">/home/<your login>/training/composer/config</code> on your host
</li>
<li class="fragment practice-constraint" data-fragment-index="2">
<code class="inline-code">/tmp/composer/config</code> inside the container
</li>
<li class="fragment practice-constraint" data-fragment-index="3">
<code class="inline-code">/home/<your login>/training/composer/cache</code> on your host
</li>
<li class="fragment practice-constraint" data-fragment-index="3">
<code class="inline-code">/tmp/composer/cache</code> inside the container
</li>
<li class="fragment practice-constraint" data-fragment-index="4">
Must be done in one line in your terminal
</li>
<br />
<li class="fragment practice-success" data-fragment-index="5">
You have an editable Symfony Skeleton in<br />
<code class="inline-code">/home/<your login>/training/my-app</code> on your host
</li>
</ul>
</div>
<aside class="notes">
<p>composer create-project symfony/skeleton app</p>
<p>COMPOSER_HOME="/path/to/config"</p>
<p>COMPOSER_CACHE_DIR="/path/to/cache"</p>
</aside>
</section>
<section>
<h2>Using Docker - Create a Symfony app</h2>
<div class="centered-slide-content">
<h3>Solution</h3>
<pre class="fragment"><code class="shell">
$ mkdir -p training/composer/config training/composer/cache
$ docker container run -i -t --rm \
-u $(id -u):$(id -g) \
-e COMPOSER_HOME="/tmp/composer/config" \
-e COMPOSER_CACHE_DIR="/tmp/composer/cache" \
--mount type=bind,source=/home/<your login>/training/composer,target=/tmp/composer \
-w /data \
--mount type=bind,source=/home/<your login>/training,target=/data \
composer:latest composer create-project symfony/skeleton my-app
</code></pre>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Publishing ports</h2>
<div class="centered-slide-content">
<ul class="fragment" data-fragment-index="1">
<li class="definition">Maps a host port number with a container port number</li>
</ul>
<br />
<br />
<pre class="fragment" data-fragment-index="2"><code class="shell">
$ docker container run --rm -u 1000:1000 \
-p 8080:8000 \
-w /data --mount type=bind,source=/home/<your login>/training/my-app,target=/data \
composer:latest php -S 0.0.0.0:8000 -t public
</code></pre>
<legend class="fragment" data-fragment-index="2">Expose the app on port 8080</legend>
</div>
<aside class="notes">
<p>Like for the volumes, the first port is on the host, the second in the container</p>
</aside>
</section>
<section>
<h2>Using Docker - Detached mode</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment definition">Runs a container as a background process</li>
</ul>
<br />
<br />
<pre class="fragment"><code class="shell">
$ docker container run --rm -u 1000:1000 \
-d \
-p 8080:8000 \
-w /data --mount type=bind,source=/home/<your login>/training/my-app,target=/data \
composer:latest php -S 0.0.0.0:8000 -t public
</code></pre>
</div>
<aside class="notes">
<p>"Detached" mode gives you the terminal back right away</p>
</aside>
</section>
<section>
<h2>Using Docker - Display logs</h2>
<div class="centered-slide-content">
<pre class="fragment" data-fragment-index="1"><code class="shell">
$ docker container logs my-app-container
</code></pre>
<pre class="fragment" data-fragment-index="2"><code class="shell">
$ docker container logs -f --tail 1 my-app-container
</code></pre>
<pre class="fragment" data-fragment-index="3"><code class="shell">
$ docker container run --name <container name>
</code></pre>
<legend class="fragment" data-fragment-index="3">Easier if we choose the container name ourselves</legend>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Manipulate a detached container</h2>
<div class="centered-slide-content">
<pre class="fragment"><code class="shell">
$ docker container exec -i -t my-app-container bash
</code></pre>
<pre class="fragment"><code class="shell">
$ docker container stop my-app-container
</code></pre>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Container isolation</h2>
<div class="centered-slide-content">
<pre class="fragment"><code class="shell">
$ docker container run --rm -u 1000:1000 -d --name my-app-container \
-w /data --mount type=bind,source=/home/<your login>/training/my-app,target=/data \
-p 8080:8000 composer:latest php -S 0.0.0.0:8000 -t public
</code></pre>
<ul>
<li class="fragment practice-question">Could you access this app from another container?</li>
</ul>
<br />
<br />
<div class="fragment">Yes, you can 👍</div>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Container isolation</h2>
<div class="centered-slide-content">
<pre><code class="shell">
$ docker container inspect
### Retrieve the IP address ###
</code></pre>
<pre class="fragment"><code class="shell">
$ docker container run -i -t --rm curlimages/curl curl <IP address>:8000
### Will display Symfony dev page ###
</code></pre>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Networks</h2>
<div class="centered-slide-content">
<ul>
<li class="fragment definition">A network allows containers to communicate with each other</li>
<li class="fragment practice-constraint">
Two containers each on a different network cannot communicate
</li>
</ul>
<br />
<br />
<pre class="fragment"><code class="shell">
$ docker network create my-network
$ docker container run -i -t --rm --network my-network \
curlimages/curl curl 172.17.0.2:8000
### You cannot access the other container anymore ###
</code></pre>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>How to use Docker</h2>
<div class="centered-slide-content">
<h3>What if we built our own custom image</h3>
<div class="fragment">Now you can use your IDE 💻</div>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Building an image</h2>
<div class="centered-slide-content">
<pre class="fragment" data-fragment-index="1"><code class="dockerfile">
FROM some-image:image-tag
</code></pre>
<legend class="fragment" data-fragment-index="1">The most basic Dockerfile you can write</legend>
<br />
<pre class="fragment" data-fragment-index="2"><code class="shell">
$ docker image build --tag my-image:my-tag .
</code></pre>
</div>
<aside class="notes">
<p>Present "builder" management command and "buildx" plugin.</p>
</aside>
</section>
<section>
<h2>Using Docker - Building an image</h2>
<div class="centered-slide-content" data-line-numbers="3">
<pre><code class="dockerfile" data-line-numbers="3|3-5|3-6">
FROM some-image:image-tag
ARG MY_ARG = "An environment variable only available at build time"
ENV MY_VAR = "An environment variable that will stay at runtime"
</code></pre>
<legend>Environment variables and arguments</legend>
<pre class="fragment"><code class="shell">
$ docker image build --build-arg MY_ARG="An overriding value" --tag my-image:my-tag .
</code></pre>
</div>
<aside class="notes"></aside>
</section>
<section>
<h2>Using Docker - Building an image</h2>
<div class="centered-slide-content" data-line-numbers="3">
<pre><code class="dockerfile" data-trim data-line-numbers="1-3">
ARG IMAGE_TAG
FROM some-image:${IMAGE_TAG}
ARG MY_ARG="An environment variable only available at build time"
ENV MY_VAR="An environment variable that will stay at runtime"
</code></pre>
<legend>Environment variables and arguments</legend>
<pre class="fragment"><code class="shell">
$ docker image build --build-arg IMAGE_TAG="image-tag" --tag my-image:my-tag .
</code></pre>
</div>
<aside class="notes">
<p>ARG is the only instruction allowed before FROM</p>
<p>Not mandatory to put a value to an ARG in the Docker file => mandatory build parameter.</p>
</aside>
</section>
<section>
<h2>Using Docker - Building an image</h2>
<div class="centered-slide-content">
<pre><code class="dockerfile" data-trim data-line-numbers="1,5|1-8">
FROM some-image:tag
ARG BUILD_OPTION="-vvv"
RUN /usr/bin/some-command
RUN /usr/bin/some-other-command ${BUILD_OPTION} && \
/usr/bin/whatever
</code></pre>
<legend>Install and configure the image through RUN</legend>
</div>
<aside class="notes">
<p>basically, run contains anything you can run in a terminal</p>
<p>Explain the concept of layers, present pros and cons of one layer vs multiple</p>
<ul>
<li>One layer → allows cleaning and keep image size under control</li>
<li>Multi layer → allows for more efficient cache, very useful to test when creating the Dockerfile</li>
</ul>
</aside>
</section>
<section>
<h2>Using Docker - Building an image</h2>
<div class="centered-slide-content">
<pre><code class="dockerfile" data-trim data-line-numbers="1|1-3|1-5|1-7|1-9|1-11">
FROM some-image:tag
COPY ./docker/some-config.ini /etc/some-config/default.ini
EXPOSE 8080
VOLUME /data
WORKDIR /tmp
USER root
</code></pre>
<legend>Add, share and expose data</legend>
</div>
<aside class="notes">
<p>COPY can also be used to copy from another Docker image</p>
</aside>
</section>
<section>
<h2>Using Docker - Building an image</h2>
<div class="centered-slide-content">
<pre><code class="dockerfile" data-trim>
FROM some-image:tag
ENV MY_VAR = "Hello!"