1
00:00:02,120 --> 00:00:04,610
<v ->When it comes to the Docker core concepts,</v>

2
00:00:04,610 --> 00:00:07,020
there are essentially two core concepts

3
00:00:07,020 --> 00:00:08,760
you have to be aware of.

4
00:00:08,760 --> 00:00:11,460
Containers and images.

5
00:00:11,460 --> 00:00:15,840
Now, containers are these isolated boxes,

6
00:00:15,840 --> 00:00:17,630
which contain our code,

7
00:00:17,630 --> 00:00:20,700
and the environment needed to run that code.

8
00:00:20,700 --> 00:00:21,970
And every container,

9
00:00:21,970 --> 00:00:23,410
and that's really important,

10
00:00:23,410 --> 00:00:26,480
is focused one task typically,

11
00:00:26,480 --> 00:00:29,290
which means we don't do multiple things

12
00:00:29,290 --> 00:00:30,400
in one container.

13
00:00:30,400 --> 00:00:32,890
We either run a web server,

14
00:00:32,890 --> 00:00:34,970
or we run a front end,

15
00:00:34,970 --> 00:00:37,080
or we run a database.

16
00:00:37,080 --> 00:00:40,730
But we don't all these things in one container.

17
00:00:40,730 --> 00:00:42,430
The idea of course is

18
00:00:42,430 --> 00:00:45,800
that we have small, lightweight packages,

19
00:00:45,800 --> 00:00:49,440
which are easy to share and reproduce, therefore.

20
00:00:49,440 --> 00:00:52,270
We have a reproducible environment locked

21
00:00:52,270 --> 00:00:54,340
into that container, after all.

22
00:00:54,340 --> 00:00:56,240
That is the main asset,

23
00:00:56,240 --> 00:00:57,410
the main selling point

24
00:00:57,410 --> 00:00:59,373
of Docker containers, in the end.

25
00:01:00,340 --> 00:01:01,790
Now, we also learned

26
00:01:01,790 --> 00:01:05,250
that these containers are kind of stateless.

27
00:01:05,250 --> 00:01:07,030
It's a term I didn't really use,

28
00:01:07,030 --> 00:01:09,600
but it means the data which is written

29
00:01:09,600 --> 00:01:12,040
in a container and that is possible,

30
00:01:12,040 --> 00:01:14,000
containers can write data,

31
00:01:14,000 --> 00:01:17,930
will be lost whenever a container is shut down.

32
00:01:17,930 --> 00:01:20,940
With the exception of volumes, of course.

33
00:01:20,940 --> 00:01:24,700
We can use volumes to kind of mirror

34
00:01:24,700 --> 00:01:28,770
or copy certain folders in our container

35
00:01:28,770 --> 00:01:31,830
to folders on our localhost machine.

36
00:01:31,830 --> 00:01:33,130
And therefore the data

37
00:01:33,130 --> 00:01:35,740
in those volumes will survive,

38
00:01:35,740 --> 00:01:38,990
even if a container is shut down.

39
00:01:38,990 --> 00:01:40,460
Now containers, as you learned,

40
00:01:40,460 --> 00:01:43,040
are created with images.

41
00:01:43,040 --> 00:01:46,890
The images are created with Dockerfiles

42
00:01:46,890 --> 00:01:49,490
or pulled from Docker Hub,

43
00:01:49,490 --> 00:01:52,800
but they are of course someone else created them

44
00:01:52,800 --> 00:01:54,100
with a Dockerfile,

45
00:01:54,100 --> 00:01:57,410
and they contain the code and the environment,

46
00:01:57,410 --> 00:02:00,120
as described in the Dockerfile.

47
00:02:00,120 --> 00:02:03,730
And then the container is just extra thin layer

48
00:02:03,730 --> 00:02:05,080
on top of the image,

49
00:02:05,080 --> 00:02:07,280
and we can run multiple containers

50
00:02:07,280 --> 00:02:08,850
on one of the same image.

51
00:02:08,850 --> 00:02:10,380
That's indeed the core idea

52
00:02:10,380 --> 00:02:12,960
behind images, that they are shareable,

53
00:02:12,960 --> 00:02:17,670
and then multiple containers can be created based on them.

54
00:02:17,670 --> 00:02:20,050
Now, therefore, they act as blueprints

55
00:02:20,050 --> 00:02:21,230
for containers,

56
00:02:21,230 --> 00:02:24,260
as I said, they contain the code and environment.

57
00:02:24,260 --> 00:02:25,580
They are read-only,

58
00:02:25,580 --> 00:02:27,870
which means that the image itself does not run.

59
00:02:27,870 --> 00:02:30,270
It does not write any code inside of it.

60
00:02:30,270 --> 00:02:32,480
If you run a container based off an image,

61
00:02:32,480 --> 00:02:35,530
and that container generates some data,

62
00:02:35,530 --> 00:02:38,230
that data is not written into the image,

63
00:02:38,230 --> 00:02:42,410
it's just written in that container read-write filesystem

64
00:02:42,410 --> 00:02:45,370
in that thin layer on top of the image.

65
00:02:45,370 --> 00:02:47,660
And therefore, the image will never change

66
00:02:47,660 --> 00:02:50,697
and can easily be built and shared with others.

67
00:02:51,610 --> 00:02:54,810
We create the image by defining these instructions,

68
00:02:54,810 --> 00:02:58,170
and that in turn creates these different layers,

69
00:02:58,170 --> 00:02:59,350
as it's called,

70
00:02:59,350 --> 00:03:00,810
which basically ensures

71
00:03:00,810 --> 00:03:03,420
that if only one instruction changes,

72
00:03:03,420 --> 00:03:06,060
not everything needs to be executed again,

73
00:03:06,060 --> 00:03:08,720
but instead these layers are cached

74
00:03:08,720 --> 00:03:10,200
and can be reused.

75
00:03:10,200 --> 00:03:14,410
And hence, building these images is efficient process

76
00:03:14,410 --> 00:03:16,540
and can be very quick.

77
00:03:16,540 --> 00:03:20,100
And then the container is just an extra thin layer

78
00:03:20,100 --> 00:03:21,460
on top of the image,

79
00:03:21,460 --> 00:03:22,990
which is created a new,

80
00:03:22,990 --> 00:03:25,520
for every new container we run.

81
00:03:25,520 --> 00:03:28,570
That, in a nutshell, is what Docker is about

82
00:03:28,570 --> 00:03:30,750
and what containers are about.

83
00:03:30,750 --> 00:03:33,713
Images and containers working together.

