1
00:00:04,480 --> 00:00:10,450
I have just demonstrated you how you are able to use variables when you need to insert, for example,

2
00:00:10,450 --> 00:00:12,700
path in the Docker run command.

3
00:00:12,700 --> 00:00:17,680
And notice that if you use variables then it is important in which folder you are located.

4
00:00:17,680 --> 00:00:25,630
If you use specifically variable because it will actually get path to current folder and place it inside

5
00:00:25,630 --> 00:00:27,100
of the Docker run command.

6
00:00:27,310 --> 00:00:27,970
Great.

7
00:00:28,000 --> 00:00:35,560
Now let me explain you actually what happens when you run container and how you are able to run container

8
00:00:35,560 --> 00:00:38,560
in background using dash option.

9
00:00:38,650 --> 00:00:43,660
Okay, let's get started with Hello world container and let's run it once again.

10
00:00:43,750 --> 00:00:45,520
Docker run.

11
00:00:45,520 --> 00:00:48,210
Hello world Enter.

12
00:00:48,340 --> 00:00:55,720
You will see this result in terminal but container exits and I have explained you before that basically

13
00:00:55,720 --> 00:01:02,260
container exits as soon as there are no processes running inside of the container.

14
00:01:02,620 --> 00:01:10,220
And in this example, there was process that has printed this text to this terminal and afterwards this

15
00:01:10,220 --> 00:01:15,650
process was terminated and Docker terminates container afterwards as well.

16
00:01:16,390 --> 00:01:20,320
Let's try to run another container, for example, Alpine.

17
00:01:20,350 --> 00:01:25,690
Let's clear our terminal and Docker run Alpine.

18
00:01:27,080 --> 00:01:28,820
Same happens here.

19
00:01:28,850 --> 00:01:31,130
Docker runs container.

20
00:01:31,160 --> 00:01:39,500
It creates process, but this process terminates and afterwards Docker terminates container as well.

21
00:01:40,130 --> 00:01:44,870
But which process actually starts in this specific container?

22
00:01:45,380 --> 00:01:49,040
Let me enter Docker history Alpine.

23
00:01:49,580 --> 00:01:52,780
And here at the top you will see command bin.

24
00:01:53,450 --> 00:01:58,160
In this case, I'll explain you what this command actually means a bit later.

25
00:01:58,160 --> 00:02:04,760
But now you should understand and remember that with this command you are able to find at the top specific

26
00:02:04,760 --> 00:02:11,780
command that is executed as soon as new container is created based on specific image.

27
00:02:11,780 --> 00:02:14,500
In this case, image name is Alpine.

28
00:02:14,510 --> 00:02:20,780
So if you create new container with Alpine image, it runs command bin.

29
00:02:21,740 --> 00:02:23,390
It is actually shell.

30
00:02:24,140 --> 00:02:33,620
But this process, this process has standard in and standard output and it weights that someone or some

31
00:02:33,620 --> 00:02:38,360
other process will connect to its standard in and standard output.

32
00:02:38,630 --> 00:02:47,240
And in such case, this process will be kept running and will accept some characters via standard input

33
00:02:47,240 --> 00:02:52,460
and may produce some output via standard output STD out.

34
00:02:52,970 --> 00:03:01,280
But if we simply run container in such way, we don't connect to standard input of this process.

35
00:03:01,820 --> 00:03:07,760
And that's why this process terminates automatically because there is no standard input connection or

36
00:03:07,760 --> 00:03:09,110
standard output connection.

37
00:03:09,320 --> 00:03:11,330
That's what happens under the hood.

38
00:03:11,420 --> 00:03:16,100
But you are able to connect to standard input of this process.

39
00:03:16,130 --> 00:03:22,070
If you'll add two flags, Dash I and Dash T, basically you could add only dash flag.

40
00:03:22,070 --> 00:03:27,020
Let me show you that Docker run dash I Alpine.

41
00:03:28,530 --> 00:03:33,550
And now I'm connected to standard in of this process bin.

42
00:03:34,530 --> 00:03:41,340
And if I'll enter, for example, LZ, I will see list of folders inside of the container.

43
00:03:41,910 --> 00:03:45,570
And if I'll go to another tab and enter Docker.

44
00:03:45,570 --> 00:03:50,570
PS I'll see list of containers that are currently up and running.

45
00:03:50,580 --> 00:03:56,370
And again I see here same command as I have shown you just in Docker history output.

46
00:03:56,460 --> 00:04:01,920
It is command that was automatically executed when container was created.

47
00:04:01,920 --> 00:04:06,480
And for this specific image alpine image, this command is been.

48
00:04:07,850 --> 00:04:16,519
But let me now try to exit from this connection to standard input of Shell inside of the container as

49
00:04:16,519 --> 00:04:21,500
usually let's try to use control C combination and you see it doesn't work.

50
00:04:21,829 --> 00:04:29,270
The reason for that is that we are connected now directly to specific process and it does not accept

51
00:04:29,270 --> 00:04:31,400
such termination commands.

52
00:04:32,520 --> 00:04:40,710
You are also able to try to stop container here using stop command like Docker stop and here maybe is

53
00:04:40,710 --> 00:04:43,410
or ID of the container or its name.

54
00:04:43,410 --> 00:04:51,420
For example this one let me copy name paste here, press enter and you will see that the docker is trying

55
00:04:51,450 --> 00:04:52,890
to stop container.

56
00:04:53,160 --> 00:04:54,450
Let's wait a bit.

57
00:04:55,130 --> 00:04:59,330
It actually sends sigterm signal to process.

58
00:04:59,360 --> 00:05:07,790
But in such case, C is running with process ID one and it doesn't accept any such kind of commands.

59
00:05:07,790 --> 00:05:15,050
And when Docker is not able to stop container during 10s, it will try to kill it.

60
00:05:15,080 --> 00:05:19,400
It is actually hard stop of the container and in such case we stop command.

61
00:05:19,400 --> 00:05:22,420
It will try to perform, let's say soft stop.

62
00:05:22,430 --> 00:05:27,260
So finally in such case in 10s Docker has stopped this container.

63
00:05:27,260 --> 00:05:31,820
And of course here in this step we have disconnected from standard input of the.

64
00:05:33,020 --> 00:05:33,620
Great.

65
00:05:33,620 --> 00:05:41,480
That's what happens when you try to connect to specific process that actually keeps container running.

66
00:05:41,480 --> 00:05:44,940
But as soon as process ends, container exits as well.

67
00:05:44,960 --> 00:05:46,340
Let's try something else.

68
00:05:46,340 --> 00:05:50,690
Let's clear terminal here and let's try to run Nginx server.

69
00:05:50,720 --> 00:05:53,000
Docker run Nginx.

70
00:05:54,530 --> 00:06:00,920
And here you see that we are actually connected to standard input of nginx process.

71
00:06:00,950 --> 00:06:02,820
We could verify that here.

72
00:06:02,840 --> 00:06:12,770
Let's go back to this step, clear it and Docker PS and we see that Nginx container is running and here

73
00:06:12,770 --> 00:06:15,530
you see basically command that was executed.

74
00:06:15,530 --> 00:06:19,580
And here is actually the name of process that is running inside of the container.

75
00:06:19,610 --> 00:06:21,920
This process name is Nginx.

76
00:06:22,600 --> 00:06:27,490
And actually here on this step, we are able to get output from this process.

77
00:06:27,490 --> 00:06:33,640
And actually in previous lectures we have seen that it produces some logs when clients connect to this

78
00:06:33,640 --> 00:06:34,490
container.

79
00:06:34,510 --> 00:06:36,250
Actually, let me show you that quickly.

80
00:06:36,250 --> 00:06:38,080
Let me terminate this container.

81
00:06:38,080 --> 00:06:42,360
Actually here I'm able to use control C and let's use port mapping.

82
00:06:42,370 --> 00:06:47,340
Docker run 80 here, we'll be 80 Nginx.

83
00:06:48,350 --> 00:06:49,160
Press enter.

84
00:06:49,160 --> 00:06:52,610
And let's now try to connect to port 80.

85
00:06:52,610 --> 00:06:53,000
80.

86
00:06:55,050 --> 00:06:59,700
And connection was successful and here Nginx has served default content.

87
00:06:59,730 --> 00:07:06,900
Let's go back to this output and here we see actually some text that was produced into standard output

88
00:07:06,900 --> 00:07:10,050
by nginx process inside of the container.

89
00:07:10,050 --> 00:07:11,520
Here is this process.

90
00:07:12,760 --> 00:07:18,160
Great, but how you are able actually to run container in background.

91
00:07:18,490 --> 00:07:27,190
You are able to use dash option and in such case those logs will be actually created and saved in background

92
00:07:27,190 --> 00:07:31,240
into log file and you will be able to observe them later on.

93
00:07:31,240 --> 00:07:38,110
But with option you will get back to terminal because container will be running in background.

94
00:07:38,140 --> 00:07:39,340
Let me show you that.

95
00:07:39,370 --> 00:07:47,740
Let me terminate this one clear terminal and here run same container but with option dash D without

96
00:07:47,740 --> 00:07:48,490
any arguments.

97
00:07:50,040 --> 00:07:54,590
And you'll simply see ID of the container that was just created.

98
00:07:54,600 --> 00:07:57,390
We could verify that here in this step Docker.

99
00:07:57,390 --> 00:08:05,370
PS You see here start characters of this ID and you see that now this container is still running because

100
00:08:05,370 --> 00:08:11,910
there is running process nginx process, but we have not connected to that process here.

101
00:08:12,570 --> 00:08:15,840
That's what actually this option does.

102
00:08:15,870 --> 00:08:22,440
With this option in place, container is started in background and you will get back to your terminal

103
00:08:22,440 --> 00:08:26,610
window, but container will be still kept running in background.

104
00:08:26,940 --> 00:08:34,140
Let me try now to connect to our web page here, Refresh page, go back here and of course, in this

105
00:08:34,140 --> 00:08:40,200
window will not see any logs because again, container is running in background, but you are able to

106
00:08:40,200 --> 00:08:47,130
read those logs using Docker logs command and use some characters from the ID of specific container

107
00:08:47,130 --> 00:08:48,480
that is up and running now.

108
00:08:48,480 --> 00:08:54,540
And I could use, for example, characters nine two that are starting characters of this ID here.

109
00:08:54,540 --> 00:09:02,550
And let's press enter and you see log that tells us that there was connection to web server and here

110
00:09:02,550 --> 00:09:04,650
is response code not modified.

111
00:09:04,680 --> 00:09:10,770
That's how you are able to get logs that were produced by specific process inside of the container.

112
00:09:10,770 --> 00:09:17,380
And again, this container enginex container is still up and running here because there is a single

113
00:09:17,380 --> 00:09:19,450
process inside of that container.

114
00:09:19,720 --> 00:09:25,750
Now you are able, if you want to stop this container using Docker stop command, let me clear terminal

115
00:09:25,750 --> 00:09:34,810
again Docker PS and get some characters from ID or use this name and use Docker stop command and type

116
00:09:34,810 --> 00:09:41,200
here for example, nine two and now you see that this container was stopped much faster than previous

117
00:09:41,200 --> 00:09:46,570
container because previously that container was not listening to any commands.

118
00:09:46,570 --> 00:09:50,710
And that's why finally in 10s process was killed automatically.

119
00:09:50,710 --> 00:09:58,510
In such case, this process enginex process listens to such commands and Docker was able to terminate

120
00:09:58,510 --> 00:10:01,480
this container in soft, let's say, manner.

121
00:10:01,870 --> 00:10:08,770
That's what option does, and that's how you're able to run such containers as, for example, Nginx

122
00:10:08,800 --> 00:10:10,030
in background.

123
00:10:10,060 --> 00:10:16,630
It will not interrupt your current terminal window and you will be able to perform any other actions,

124
00:10:16,630 --> 00:10:18,760
create other containers and so on.

125
00:10:19,180 --> 00:10:19,810
Great.

126
00:10:19,810 --> 00:10:21,190
That's all for this lecture.

127
00:10:21,190 --> 00:10:27,940
And in the next one let me demonstrate you how you are able to run multiple containers simultaneously

128
00:10:27,940 --> 00:10:29,650
using same image.

129
00:10:29,950 --> 00:10:31,000
Let's do that next.

130
00:10:31,000 --> 00:10:31,570
Bye bye.

