1
00:00:02,200 --> 00:00:07,140
I mentioned that containers are based on images.

2
00:00:07,140 --> 00:00:09,630
And actually, there will be two ways

3
00:00:09,630 --> 00:00:12,100
of creating or getting an image

4
00:00:12,100 --> 00:00:14,220
so that we then can run a container.

5
00:00:14,220 --> 00:00:18,810
The first way is that we use an already existing image.

6
00:00:18,810 --> 00:00:22,210
For example, because a colleague of ours already built it,

7
00:00:22,210 --> 00:00:25,030
or also very common, because we use

8
00:00:25,030 --> 00:00:28,310
one of the official pre-built images

9
00:00:28,310 --> 00:00:31,680
or one of the images shared by the community.

10
00:00:31,680 --> 00:00:34,950
And a great source for that would be Docker Hub,

11
00:00:34,950 --> 00:00:39,330
which you can simply Google to find hub.docker.com.

12
00:00:39,330 --> 00:00:41,540
And there you can log in

13
00:00:41,540 --> 00:00:44,010
but you don't need to do this right now.

14
00:00:44,010 --> 00:00:45,870
Instead, here in the search bar,

15
00:00:45,870 --> 00:00:48,910
we can, for example, search for node.

16
00:00:48,910 --> 00:00:53,400
And what we'll find is the official node Docker image,

17
00:00:53,400 --> 00:00:57,880
which we could use to build a node application container,

18
00:00:57,880 --> 00:01:01,723
a container which will later run a node application.

19
00:01:02,790 --> 00:01:07,540
Now this node image which you find on Docker Hub,

20
00:01:07,540 --> 00:01:12,510
can be used by anyone and it is distributed and created

21
00:01:12,510 --> 00:01:16,570
and maintained by the official node team.

22
00:01:16,570 --> 00:01:20,790
Now we will use such official images a lot throughout

23
00:01:20,790 --> 00:01:24,900
this course and in general when working with Docker,

24
00:01:24,900 --> 00:01:28,270
but we can especially use it right away to get started

25
00:01:28,270 --> 00:01:30,680
with images and containers here.

26
00:01:30,680 --> 00:01:33,950
And all we need to do for that is open up

27
00:01:33,950 --> 00:01:38,950
the command prompt or terminal on your system

28
00:01:39,040 --> 00:01:43,490
and then navigate in any folder of your choice

29
00:01:43,490 --> 00:01:48,053
and run docker run node.

30
00:01:49,680 --> 00:01:54,050
This command here will use this node image

31
00:01:54,050 --> 00:01:59,050
which we find on Docker Hub and it will utilize it

32
00:01:59,460 --> 00:02:04,060
to create a so called container based on this image,

33
00:02:04,060 --> 00:02:07,320
because as I mentioned, containers are really just

34
00:02:07,320 --> 00:02:10,550
the running instances of images.

35
00:02:10,550 --> 00:02:14,550
Images contain the setup code the environment,

36
00:02:14,550 --> 00:02:18,490
in this case, the node image contains the node installation.

37
00:02:18,490 --> 00:02:22,890
And then we can run the image to run the application

38
00:02:22,890 --> 00:02:27,890
or in this case, to simply run the node interactive shell.

39
00:02:29,990 --> 00:02:33,020
Now if you hit Enter, this will give you an error

40
00:02:33,020 --> 00:02:35,680
that it doesn't find this image locally,

41
00:02:35,680 --> 00:02:38,110
which makes sense because it's on Docker Hub,

42
00:02:38,110 --> 00:02:42,520
and then it'll automatically pull it from Docker Hub.

43
00:02:42,520 --> 00:02:47,520
So now this downloads the latest node image from Docker Hub

44
00:02:48,100 --> 00:02:52,430
and once it downloaded it locally onto our machine,

45
00:02:52,430 --> 00:02:55,820
it will run this image as a container.

46
00:02:55,820 --> 00:02:58,200
So let's wait for this download to finish here

47
00:03:00,200 --> 00:03:03,930
and thereafter, you will see nothing special here.

48
00:03:03,930 --> 00:03:07,070
It's done and we can enter more commands.

49
00:03:07,070 --> 00:03:10,390
So did we now run the container?

50
00:03:10,390 --> 00:03:13,173
Did we now create a container based on an image?

51
00:03:14,040 --> 00:03:15,500
Well, yes, we did.

52
00:03:15,500 --> 00:03:18,270
But this container isn't really doing much.

53
00:03:18,270 --> 00:03:22,740
Node is of course just a software you could say

54
00:03:22,740 --> 00:03:27,740
and indeed we can execute node to get an interactive shell

55
00:03:28,040 --> 00:03:30,160
where we can insert command.

56
00:03:30,160 --> 00:03:33,380
But by default, and that's important,

57
00:03:33,380 --> 00:03:37,630
a container is isolated from the surrounding environment

58
00:03:37,630 --> 00:03:40,970
and just because there might be some interactive shell

59
00:03:40,970 --> 00:03:43,160
running inside of a container

60
00:03:43,160 --> 00:03:48,160
does not mean that this shell is exposed to us as a user.

61
00:03:49,730 --> 00:03:53,060
Nonetheless, this container was created.

62
00:03:53,060 --> 00:03:57,630
And you can tell by running Docker PS dash A.

63
00:03:57,630 --> 00:04:02,140
PS stands for processes and with the dash A flag,

64
00:04:02,140 --> 00:04:06,290
this will show you all the processes all the containers

65
00:04:06,290 --> 00:04:08,450
Docker created for us.

66
00:04:08,450 --> 00:04:12,045
And if you hit enter, you will see that a minute ago

67
00:04:12,045 --> 00:04:15,760
I actually created a container.

68
00:04:15,760 --> 00:04:17,120
And to make this a bit easier to read

69
00:04:17,120 --> 00:04:19,403
I'll zoom out a bit and rerun this.

70
00:04:20,440 --> 00:04:24,280
And you'll see we created a container with this ID.

71
00:04:24,280 --> 00:04:27,150
The image was the node image.

72
00:04:27,150 --> 00:04:29,570
It was created two minutes ago,

73
00:04:29,570 --> 00:04:32,550
it exited so it's not running anymore

74
00:04:32,550 --> 00:04:36,070
and it also received a automatically generated name.

75
00:04:36,070 --> 00:04:39,260
We'll dive into names and into configuring containers

76
00:04:39,260 --> 00:04:42,410
in general in greater detail later.

77
00:04:42,410 --> 00:04:44,690
But what we see is that something happened

78
00:04:44,690 --> 00:04:46,700
but that it's not running anymore

79
00:04:46,700 --> 00:04:50,350
because as I said a container runs in isolation.

80
00:04:50,350 --> 00:04:55,350
And even though we executed node as a image

81
00:04:55,800 --> 00:04:58,630
or as a container based on the node image,

82
00:04:58,630 --> 00:05:00,510
this alone doesn't do much.

83
00:05:00,510 --> 00:05:04,360
Because the interactive shell exposed by node

84
00:05:04,360 --> 00:05:08,960
is not automatically exposed by the container to us.

85
00:05:08,960 --> 00:05:12,140
That is something we can change though.

86
00:05:12,140 --> 00:05:16,630
If we repeat the command from before, docker run node,

87
00:05:16,630 --> 00:05:19,800
and we now add an extra flag in front of node,

88
00:05:19,800 --> 00:05:24,040
the dash IT flag, then we will actually tell Docker

89
00:05:24,040 --> 00:05:28,090
that we wanna expose an interactive session

90
00:05:28,090 --> 00:05:31,710
from inside the container to our hosting machine.

91
00:05:31,710 --> 00:05:33,980
And hence if we now hit enter,

92
00:05:33,980 --> 00:05:38,450
we actually are in that interactive node terminal

93
00:05:38,450 --> 00:05:41,520
where we can run basic node commands.

94
00:05:41,520 --> 00:05:43,290
For example, one plus one,

95
00:05:43,290 --> 00:05:45,980
but we could also use node API's in here.

96
00:05:45,980 --> 00:05:50,610
But that's of course not the focus of this session.

97
00:05:50,610 --> 00:05:53,740
Now the important thing about this here is that

98
00:05:53,740 --> 00:05:58,450
node here is now running inside of that created container

99
00:05:58,450 --> 00:06:02,730
and it's just exposed to us by adding this extra flag

100
00:06:02,730 --> 00:06:05,150
so we can interact with that container

101
00:06:05,150 --> 00:06:08,480
and with node running in the container.

102
00:06:08,480 --> 00:06:12,560
Node is not running on our machine here

103
00:06:12,560 --> 00:06:14,120
and I can prove this.

104
00:06:14,120 --> 00:06:18,490
Please note that here we're interacting with node 14.9,

105
00:06:18,490 --> 00:06:22,130
which is the version that at the moment I was recording this

106
00:06:22,130 --> 00:06:24,400
was pulled into this image,

107
00:06:24,400 --> 00:06:27,620
and therefore is being used in this container.

108
00:06:27,620 --> 00:06:32,320
Now if I quit this process with Control + C pressed twice

109
00:06:32,320 --> 00:06:34,620
now the container will shut down,

110
00:06:34,620 --> 00:06:38,440
when I quit this and I run node dash V here

111
00:06:38,440 --> 00:06:42,650
like this on my system so not inside of the container,

112
00:06:42,650 --> 00:06:45,170
I see 14.7 as a version.

113
00:06:45,170 --> 00:06:49,250
So locally on my system I got a different version installed,

114
00:06:49,250 --> 00:06:51,690
then the version we interacted with here,

115
00:06:51,690 --> 00:06:55,200
which proves that the version we did interact with

116
00:06:55,200 --> 00:06:58,190
must be the version from inside the container.

117
00:06:58,190 --> 00:07:02,650
And we don't need node to be installed on our system at all

118
00:07:02,650 --> 00:07:05,480
in order to be able to run this node container

119
00:07:05,480 --> 00:07:06,803
and interact with it.

120
00:07:07,740 --> 00:07:11,310
And that is really how you work with containers.

121
00:07:11,310 --> 00:07:13,760
At least these are some first steps

122
00:07:13,760 --> 00:07:15,710
of working with containers,

123
00:07:15,710 --> 00:07:19,590
and this also shows us what images and containers are.

124
00:07:19,590 --> 00:07:22,920
Images are used behind the scenes

125
00:07:22,920 --> 00:07:26,770
to hold all the logic and all the code a container needs,

126
00:07:26,770 --> 00:07:30,600
and then we create instances of an image

127
00:07:30,600 --> 00:07:32,420
with the Run command.

128
00:07:32,420 --> 00:07:35,070
This creates then the concrete containers

129
00:07:35,070 --> 00:07:37,400
which are based on an image.

130
00:07:37,400 --> 00:07:42,350
And if we now run Docker PS dash A again,

131
00:07:42,350 --> 00:07:45,370
we see that we get two containers now.

132
00:07:45,370 --> 00:07:49,330
Both are not running anymore, they have been exited.

133
00:07:49,330 --> 00:07:53,990
But we have more than one container based on the same image.

134
00:07:53,990 --> 00:07:57,090
Both containers are based on the same image.

135
00:07:57,090 --> 00:07:59,520
And yes, they are not running anymore

136
00:07:59,520 --> 00:08:03,100
but we could absolutely have two containers which are based

137
00:08:03,100 --> 00:08:06,360
on the same image up and running at the same point of time,

138
00:08:06,360 --> 00:08:09,220
simply by opening up multiple terminals

139
00:08:09,220 --> 00:08:12,660
and then while repeating this docker run command.

140
00:08:12,660 --> 00:08:14,940
This would absolutely be possible.

141
00:08:14,940 --> 00:08:17,780
And that's the idea behind images and containers.

142
00:08:17,780 --> 00:08:21,860
Images contain the code, the setup, the meet, you could say

143
00:08:21,860 --> 00:08:25,027
and containers are then the running instances

144
00:08:25,027 --> 00:08:26,503
of those images.

