1
00:00:02,130 --> 00:00:06,300
Now to create this utility container, I need my own image.

2
00:00:06,300 --> 00:00:08,620
And therefore I'll add a Docker file.

3
00:00:08,620 --> 00:00:11,930
Now I wanna start based on node again.

4
00:00:11,930 --> 00:00:16,079
And I will actually pick a specific node version here,

5
00:00:16,079 --> 00:00:19,070
I'll use the 14 dash Alpine version,

6
00:00:19,070 --> 00:00:21,790
that's still node version 14,

7
00:00:21,790 --> 00:00:25,610
but it's using an extra slim operating system layer

8
00:00:25,610 --> 00:00:26,450
under the hood.

9
00:00:26,450 --> 00:00:29,040
So it will simply be a smaller node image.

10
00:00:29,040 --> 00:00:31,540
Of course, we could also just use node.

11
00:00:31,540 --> 00:00:33,970
But since I want to build a utility container,

12
00:00:33,970 --> 00:00:36,420
I want an extra slim setup here.

13
00:00:36,420 --> 00:00:38,380
So I'll use this Alpine version,

14
00:00:38,380 --> 00:00:43,030
which is this very slim and optimized node base image.

15
00:00:43,030 --> 00:00:45,690
Now with that, we can add a working directory

16
00:00:45,690 --> 00:00:49,470
and set this to app, for example, to define

17
00:00:49,470 --> 00:00:52,190
which folder will be used by commands

18
00:00:52,190 --> 00:00:54,920
executed on this container and on this image,

19
00:00:54,920 --> 00:00:59,580
and that includes commands you entered with Docker run,

20
00:00:59,580 --> 00:01:01,490
anything which you enter after the image name

21
00:01:01,490 --> 00:01:05,099
will also run against this default working directory.

22
00:01:05,099 --> 00:01:07,560
And then we could specify a starting command here,

23
00:01:07,560 --> 00:01:10,160
for example, NPM init.

24
00:01:10,160 --> 00:01:14,710
But I want to make my project here more flexible than that,

25
00:01:14,710 --> 00:01:17,710
I don't want to restrict this image to just being able

26
00:01:17,710 --> 00:01:20,560
to run the init command,

27
00:01:20,560 --> 00:01:25,240
I want to give the user full control over this image

28
00:01:25,240 --> 00:01:28,920
and allow the user to run any command against this image.

29
00:01:28,920 --> 00:01:31,170
So I'll just save it like this.

30
00:01:31,170 --> 00:01:36,170
And then I'll build this and give it a tag of node util

31
00:01:36,310 --> 00:01:37,653
for node utility.

32
00:01:39,230 --> 00:01:42,950
And this will now download this node Alpine image,

33
00:01:42,950 --> 00:01:47,540
which is super small as you can tell only 35 megabytes here,

34
00:01:47,540 --> 00:01:50,210
and it will then build this.

35
00:01:50,210 --> 00:01:55,210
And thereafter, we can Docker run our node util, image,

36
00:01:56,530 --> 00:01:59,440
and then for example, pass in NPM init.

37
00:02:00,600 --> 00:02:03,610
Now, again, we need to do this in interactive mode,

38
00:02:03,610 --> 00:02:07,350
to stay connected and to be able to enter values.

39
00:02:07,350 --> 00:02:10,400
But I also wanna do more than that, by default,

40
00:02:10,400 --> 00:02:12,690
this command would run in the app folder

41
00:02:12,690 --> 00:02:14,370
inside of the container.

42
00:02:14,370 --> 00:02:19,160
Now I want to mirror it to my local folder

43
00:02:19,160 --> 00:02:21,880
so that what I create in the container

44
00:02:21,880 --> 00:02:25,200
is also available here on my host machine.

45
00:02:25,200 --> 00:02:28,470
So that I can create a project on my host machine

46
00:02:28,470 --> 00:02:30,240
with help of a container.

47
00:02:30,240 --> 00:02:33,290
That's the idea behind having a utility container,

48
00:02:33,290 --> 00:02:35,820
we can use it to execute something

49
00:02:35,820 --> 00:02:38,300
which has an effect on the host machine

50
00:02:38,300 --> 00:02:41,150
without having to install all the extra tools

51
00:02:41,150 --> 00:02:42,870
on the host machine.

52
00:02:42,870 --> 00:02:44,700
And we can use a feature for that,

53
00:02:44,700 --> 00:02:47,730
which we already used many times before in the course,

54
00:02:47,730 --> 00:02:50,980
we can use a bind mount with dash v here.

55
00:02:50,980 --> 00:02:53,540
And I can bind my folder here

56
00:02:53,540 --> 00:02:56,870
to the working directory I have in there.

57
00:02:56,870 --> 00:03:00,033
So I'll just copy this path here.

58
00:03:01,663 --> 00:03:05,710
And specify unspecified that without the file name,

59
00:03:05,710 --> 00:03:08,400
and then a colon and then the path inside

60
00:03:08,400 --> 00:03:11,293
of the container/app,

61
00:03:12,190 --> 00:03:13,650
which is the working directory

62
00:03:13,650 --> 00:03:15,393
in which NPM init will run.

63
00:03:16,920 --> 00:03:20,580
And now if we hit enter, we start this container.

64
00:03:20,580 --> 00:03:23,910
Now we have to fill out these questions

65
00:03:23,910 --> 00:03:25,430
we have to provide answers,

66
00:03:25,430 --> 00:03:28,950
we can use some default values here if you want to.

67
00:03:28,950 --> 00:03:32,210
And once we're done, you see the package JSON file appear

68
00:03:32,210 --> 00:03:34,480
here on my host machine.

69
00:03:34,480 --> 00:03:37,370
So in this project folder on my host machine,

70
00:03:37,370 --> 00:03:39,180
because of this bind mount,

71
00:03:39,180 --> 00:03:42,980
we're sharing our host machine folder here

72
00:03:42,980 --> 00:03:45,750
with the folder inside of the container.

73
00:03:45,750 --> 00:03:48,940
And commands which we execute inside of the container

74
00:03:48,940 --> 00:03:52,750
inside of this shared folder they offer also have an effect

75
00:03:52,750 --> 00:03:54,840
on our host machine.

76
00:03:54,840 --> 00:03:57,870
And now I could totally uninstalled node

77
00:03:57,870 --> 00:04:00,550
and NPM on my host machine.

78
00:04:00,550 --> 00:04:04,410
And I could still create projects with help of NPM init

79
00:04:04,410 --> 00:04:07,970
with help of this utility container.

80
00:04:07,970 --> 00:04:12,560
And that might sound like a constructed or dumb scenario.

81
00:04:12,560 --> 00:04:15,290
But actually it can be really useful

82
00:04:15,290 --> 00:04:17,839
that you don't have to install all these extra tools

83
00:04:17,839 --> 00:04:18,940
on your machine.

84
00:04:18,940 --> 00:04:20,829
For node It's not too bad.

85
00:04:20,829 --> 00:04:24,950
It's just one tool node JS But for Laravel and PHP,

86
00:04:24,950 --> 00:04:27,610
as I mentioned, it will be way more complex.

87
00:04:27,610 --> 00:04:29,380
And I'll come back to that example

88
00:04:29,380 --> 00:04:32,900
and show you a Laravel PHP setup with help of Docker

89
00:04:32,900 --> 00:04:34,720
once we're done with this section,

90
00:04:34,720 --> 00:04:37,083
because that will always be quite interesting.

91
00:04:38,010 --> 00:04:41,080
But as I just said once we're done with this section,

92
00:04:41,080 --> 00:04:44,460
because there actually are a couple of other neat features

93
00:04:44,460 --> 00:04:47,770
which can make working with such utility containers

94
00:04:47,770 --> 00:04:49,023
more convenient.

