1
00:00:01,507 --> 00:00:04,350
Now for that I open my Terminal here

2
00:00:04,350 --> 00:00:06,250
and I wanna start simple.

3
00:00:06,250 --> 00:00:09,970
I will run the node image just like this

4
00:00:09,970 --> 00:00:11,420
and keep in mind that node

5
00:00:11,420 --> 00:00:14,060
is an official image from Docker Hub.

6
00:00:14,060 --> 00:00:17,370
Now, if i execute this, it just starts.

7
00:00:17,370 --> 00:00:19,290
And immediately it stops.

8
00:00:19,290 --> 00:00:21,610
Because this is an image which we need to start

9
00:00:21,610 --> 00:00:26,400
in interactive mode so that it expects some input from us.

10
00:00:26,400 --> 00:00:29,200
And then it starts and we can execute

11
00:00:29,200 --> 00:00:32,870
some basic commands in node here.

12
00:00:32,870 --> 00:00:34,840
We can use it as a calculator

13
00:00:34,840 --> 00:00:38,070
but we can also run other node commands here.

14
00:00:38,070 --> 00:00:40,460
It's not the primary thing I wanna do here.

15
00:00:40,460 --> 00:00:41,490
I just wanna highlight

16
00:00:41,490 --> 00:00:44,420
that we can start this node container like that.

17
00:00:44,420 --> 00:00:46,100
It is something we did earlier

18
00:00:46,100 --> 00:00:48,070
in the course at the beginning.

19
00:00:48,070 --> 00:00:51,010
Now we can quit this by pressing CONTROL C twice.

20
00:00:51,010 --> 00:00:53,370
This will then also shuts down the container

21
00:00:53,370 --> 00:00:56,960
which is why we now see it here under stopped containers.

22
00:00:56,960 --> 00:00:59,680
And of course, with Docker container prune

23
00:00:59,680 --> 00:01:02,450
we can remove all those stopped containers.

24
00:01:02,450 --> 00:01:06,040
Okay, so that's how we can run a container.

25
00:01:06,040 --> 00:01:09,290
Now i will do something which might look strange at first.

26
00:01:09,290 --> 00:01:11,630
I'm going to run this node container again

27
00:01:11,630 --> 00:01:14,940
in interactive mode, but also in detached mode.

28
00:01:14,940 --> 00:01:17,700
That means we can't enter commands like this

29
00:01:17,700 --> 00:01:21,810
but internally this containers still is waiting for input,

30
00:01:21,810 --> 00:01:24,170
which will keep it up and running.

31
00:01:24,170 --> 00:01:26,160
So now this containers started.

32
00:01:26,160 --> 00:01:27,750
Hence we can see it here

33
00:01:27,750 --> 00:01:32,750
under this auto assigned name, under running containers.

34
00:01:32,770 --> 00:01:34,370
And now I wanna show you a command

35
00:01:34,370 --> 00:01:36,540
which we haven't used thus far.

36
00:01:36,540 --> 00:01:39,830
And that's the Docker exec command.

37
00:01:39,830 --> 00:01:43,310
The Docker exec command allows you to execute

38
00:01:43,310 --> 00:01:46,860
certain commands inside of a running container

39
00:01:46,860 --> 00:01:51,410
besides the default command, this container executes.

40
00:01:51,410 --> 00:01:54,460
So besides the command that might've been specified

41
00:01:54,460 --> 00:01:58,060
in a Docker file, that command still continues running.

42
00:01:58,060 --> 00:02:00,690
So the application still continues to run

43
00:02:00,690 --> 00:02:04,283
but you can't run additional commands inside of a container.

44
00:02:05,170 --> 00:02:08,330
That's something which sometimes could be useful.

45
00:02:08,330 --> 00:02:11,320
Now to use this command we need the name of a container

46
00:02:11,320 --> 00:02:12,720
of a running container.

47
00:02:12,720 --> 00:02:16,770
And then we can execute a command against that container.

48
00:02:16,770 --> 00:02:18,970
And we could try running npm init

49
00:02:18,970 --> 00:02:22,623
which creates a node project in that running node container.

50
00:02:23,850 --> 00:02:27,120
And you actually see that it started asking me

51
00:02:27,120 --> 00:02:30,200
some questions but then it finished immediately

52
00:02:30,200 --> 00:02:33,700
because exec just like run needs to be started

53
00:02:33,700 --> 00:02:37,370
in interactive mode if you want to stay connected

54
00:02:37,370 --> 00:02:39,730
to that process, you're starting up here

55
00:02:39,730 --> 00:02:42,340
and if you want to be able to provide input.

56
00:02:42,340 --> 00:02:44,070
So just as with run,

57
00:02:44,070 --> 00:02:48,000
we can add the dash IT Flag here on exec

58
00:02:48,000 --> 00:02:51,040
then execute a command against this container

59
00:02:51,040 --> 00:02:54,520
and execute the npm init command against it.

60
00:02:54,520 --> 00:02:56,090
And if we now hit Enter

61
00:02:56,090 --> 00:02:58,990
I'm walked through these questions here

62
00:02:58,990 --> 00:03:01,500
where I provide a name and some other settings

63
00:03:01,500 --> 00:03:05,120
to a new project which is now created

64
00:03:05,120 --> 00:03:06,753
inside of that container.

65
00:03:07,600 --> 00:03:10,920
And now that means that we can run this command

66
00:03:10,920 --> 00:03:14,420
without node and npm being installed in our system

67
00:03:14,420 --> 00:03:17,930
because it runs inside of this container.

68
00:03:17,930 --> 00:03:21,660
Now that's still not too useful here because

69
00:03:21,660 --> 00:03:23,400
well if it's in the container,

70
00:03:23,400 --> 00:03:25,410
we created the project in here

71
00:03:25,410 --> 00:03:27,670
and we have no access to that project

72
00:03:27,670 --> 00:03:32,130
but it's just a first demo showing you what we can do.

73
00:03:32,130 --> 00:03:35,970
There's also is one AVR syntax that can be interesting.

74
00:03:35,970 --> 00:03:39,050
Let's stop this container.

75
00:03:39,050 --> 00:03:41,630
So let's stop this container by its name

76
00:03:43,170 --> 00:03:45,450
and thereafter, let's start it again

77
00:03:45,450 --> 00:03:47,770
but let's start it differently

78
00:03:47,770 --> 00:03:51,150
with Docker exec we can execute commands

79
00:03:51,150 --> 00:03:53,850
in a running container without interrupting

80
00:03:53,850 --> 00:03:57,800
the default command which starts when the container starts.

81
00:03:57,800 --> 00:04:01,580
We also can override that default command though.

82
00:04:01,580 --> 00:04:03,440
Now, when we start the node container

83
00:04:03,440 --> 00:04:06,040
the default command that is executed

84
00:04:06,040 --> 00:04:10,750
in the container is the node executable itself

85
00:04:10,750 --> 00:04:12,800
which enters the so called a Rebel

86
00:04:12,800 --> 00:04:15,020
which is just an interactive mode

87
00:04:15,020 --> 00:04:17,070
where we can run node commands.

88
00:04:17,070 --> 00:04:18,529
That's the default command,

89
00:04:18,529 --> 00:04:22,560
the node image will execute when we started.

90
00:04:22,560 --> 00:04:25,760
And if we use interactive mode, we stay connected

91
00:04:25,760 --> 00:04:30,760
and we can then work with that interactive node input mode.

92
00:04:31,000 --> 00:04:33,530
Now we can override this default command

93
00:04:33,530 --> 00:04:37,060
by adding a new command after the image name.

94
00:04:37,060 --> 00:04:40,440
And that's another syntax we haven't used thus far.

95
00:04:40,440 --> 00:04:43,530
And here I could then specify npm init

96
00:04:43,530 --> 00:04:46,010
to overwrite the default command

97
00:04:46,010 --> 00:04:49,280
which would be to go into this interactive

98
00:04:49,280 --> 00:04:54,280
enter some node code mode and instead execute npm init.

99
00:04:54,680 --> 00:04:58,860
If I now hit Enter we again are prompted to provide

100
00:04:58,860 --> 00:05:01,870
the configuration for this node project,

101
00:05:01,870 --> 00:05:03,907
which we create with npm init.

102
00:05:03,907 --> 00:05:07,530
And if I now hit enter this finishes and therefore,

103
00:05:07,530 --> 00:05:10,070
it also stopped the container thereafter

104
00:05:10,070 --> 00:05:12,980
because we overrode the default command

105
00:05:12,980 --> 00:05:16,650
which would have opened this ongoing node interactive mode

106
00:05:16,650 --> 00:05:20,570
with the npm init command, which just creates a project

107
00:05:20,570 --> 00:05:22,493
and then stops once it finished.

108
00:05:23,370 --> 00:05:25,890
And at this moment, that's all not too useful.

109
00:05:25,890 --> 00:05:28,140
I'm just getting started with these commands

110
00:05:28,140 --> 00:05:32,110
to make you aware of this feature Docker also offers.

111
00:05:32,110 --> 00:05:34,930
Docker exec could be useful for example

112
00:05:34,930 --> 00:05:37,760
to read some log files, which were written inside

113
00:05:37,760 --> 00:05:41,640
of a container without interrupting the main process.

114
00:05:41,640 --> 00:05:44,170
But now did we know about these commands?

115
00:05:44,170 --> 00:05:48,030
Let's build a utility Docker container

116
00:05:48,030 --> 00:05:51,030
or image and then a container based on that.

117
00:05:51,030 --> 00:05:54,403
And let's see how that actually may help us.

