1
00:00:02,200 --> 00:00:06,020
Now for this course section, I got another small example,

2
00:00:06,020 --> 00:00:08,440
which you again find attached.

3
00:00:08,440 --> 00:00:13,250
It's a very simple note JS API application again,

4
00:00:13,250 --> 00:00:15,910
with one note JS file.

5
00:00:15,910 --> 00:00:19,030
This app JS file, where we in the end again

6
00:00:19,030 --> 00:00:23,420
create a node server and listen 3000 in this case

7
00:00:23,420 --> 00:00:26,570
and where we then have two end points.

8
00:00:26,570 --> 00:00:30,970
We handle gets requests to our domain slash story.

9
00:00:30,970 --> 00:00:35,323
And we handle post requests to our domain slash story.

10
00:00:36,170 --> 00:00:39,040
And here in the post request handler,

11
00:00:39,040 --> 00:00:41,430
we in the end extract some text

12
00:00:41,430 --> 00:00:43,300
out of the incoming request.

13
00:00:43,300 --> 00:00:45,250
We check whether it's empty or not,

14
00:00:45,250 --> 00:00:50,080
and if it's not empty, we appended it to a file

15
00:00:50,080 --> 00:00:51,920
in our file path,

16
00:00:51,920 --> 00:00:53,640
which is this one here.

17
00:00:53,640 --> 00:00:56,720
Which in the end means we're looking for a story folder

18
00:00:56,720 --> 00:00:59,860
and in there a text dot text file.

19
00:00:59,860 --> 00:01:03,710
And there we add the text sent by the user

20
00:01:03,710 --> 00:01:05,163
through this request.

21
00:01:06,100 --> 00:01:09,460
Well, and forward to get route for this get request,

22
00:01:09,460 --> 00:01:10,420
which we're handling,

23
00:01:10,420 --> 00:01:12,310
We are reading that file

24
00:01:12,310 --> 00:01:15,510
and we are returning the data which we read.

25
00:01:15,510 --> 00:01:17,750
This is a very simple application

26
00:01:17,750 --> 00:01:19,860
and it will in the end to write data

27
00:01:19,860 --> 00:01:22,950
to this text text file into the story folder,

28
00:01:22,950 --> 00:01:25,493
which initially is empty of course.

29
00:01:26,440 --> 00:01:28,870
And so that we can see this in action,

30
00:01:28,870 --> 00:01:31,180
I prepared a Docker file

31
00:01:31,180 --> 00:01:33,800
for building this node application image

32
00:01:33,800 --> 00:01:37,160
and a Docker compose file for running that image

33
00:01:37,160 --> 00:01:40,540
and for building it and starting to build process as well

34
00:01:40,540 --> 00:01:43,950
because here I'm using volumes.

35
00:01:43,950 --> 00:01:48,000
Because of course I got some data into story folder here

36
00:01:48,000 --> 00:01:51,823
which showed survive container removal and restarts.

37
00:01:52,870 --> 00:01:55,500
And of course we could also just run our image

38
00:01:55,500 --> 00:02:00,290
with Docker run, and add a volume with the dash V flag

39
00:02:00,290 --> 00:02:02,920
but so that we don't have to write this

40
00:02:02,920 --> 00:02:04,510
a bit longer command,

41
00:02:04,510 --> 00:02:07,563
I prepared this Docker compose yammer file.

42
00:02:09,100 --> 00:02:10,680
So what we can do here

43
00:02:10,680 --> 00:02:15,110
is we can now run Docker compose up dash D

44
00:02:15,110 --> 00:02:16,860
maybe all the dash dash build

45
00:02:16,860 --> 00:02:21,070
to always ensure that the image is reevaluated

46
00:02:21,070 --> 00:02:24,340
and possibly rebuilt if something changed.

47
00:02:24,340 --> 00:02:25,830
And once that is up and running,

48
00:02:25,830 --> 00:02:27,580
you can use a tool like postman

49
00:02:27,580 --> 00:02:30,440
to send requests to this dockerized

50
00:02:30,440 --> 00:02:32,590
and now running application.

51
00:02:32,590 --> 00:02:36,340
For example, I gets request to local host slash story,

52
00:02:36,340 --> 00:02:38,380
to get any safe stories.

53
00:02:38,380 --> 00:02:42,800
And initially of course, that returns a valid response

54
00:02:42,800 --> 00:02:44,840
but an empty string here,

55
00:02:44,840 --> 00:02:47,780
but you can also send a post request

56
00:02:47,780 --> 00:02:50,440
to local host slash story,

57
00:02:50,440 --> 00:02:55,130
and then go to body and add a raw JSON body here.

58
00:02:55,130 --> 00:02:58,690
And then between curly braces and double quotes,

59
00:02:58,690 --> 00:03:02,698
add text like my text and send this

60
00:03:02,698 --> 00:03:05,310
and this will now be stored.

61
00:03:05,310 --> 00:03:09,230
And if you now reload or a resend to get request

62
00:03:09,230 --> 00:03:10,540
you see your text,

63
00:03:10,540 --> 00:03:13,960
and then this line break which is automatically added

64
00:03:13,960 --> 00:03:17,120
by the node JS code here

65
00:03:17,120 --> 00:03:20,263
when you store and use story here.

66
00:03:21,290 --> 00:03:23,510
So this works and of course

67
00:03:23,510 --> 00:03:25,460
since we're using a volume,

68
00:03:25,460 --> 00:03:28,800
if we run Docker compose down

69
00:03:28,800 --> 00:03:32,210
and therefore the container gets removed in the end

70
00:03:32,210 --> 00:03:36,050
it gets stopped and all the remove.

71
00:03:36,050 --> 00:03:38,130
We can of course ensure that everything

72
00:03:38,130 --> 00:03:40,600
what we have on containers is removed

73
00:03:40,600 --> 00:03:42,850
by running Docker container prune

74
00:03:42,850 --> 00:03:45,730
and then entering why to confirm this.

75
00:03:45,730 --> 00:03:47,510
So if that is all removed,

76
00:03:47,510 --> 00:03:51,320
if we rerun the up command Docker compose up,

77
00:03:51,320 --> 00:03:54,650
of course we'll see that if we sent this get request again

78
00:03:54,650 --> 00:03:57,440
this data is still there.

79
00:03:57,440 --> 00:04:00,090
Because even though the container was stopped

80
00:04:00,090 --> 00:04:02,820
and removed with the help of a volume,

81
00:04:02,820 --> 00:04:05,690
it was stored and therefore persisted.

82
00:04:05,690 --> 00:04:07,340
And that's not something new,

83
00:04:07,340 --> 00:04:10,080
that is something you already did learn about earlier

84
00:04:10,080 --> 00:04:10,930
on in the course,

85
00:04:10,930 --> 00:04:13,760
we learned how to work with volumes.

86
00:04:13,760 --> 00:04:16,800
And we learned that volumes are a powerful tool

87
00:04:16,800 --> 00:04:19,779
when working with Docker because volumes allow us

88
00:04:19,779 --> 00:04:23,190
to process data across container restarts

89
00:04:23,190 --> 00:04:25,513
and especially removals.

90
00:04:26,660 --> 00:04:29,890
So with that, I'm going to run Docker compose down again,

91
00:04:29,890 --> 00:04:32,150
to stop this container again.

92
00:04:32,150 --> 00:04:35,570
And I'm now going to dive into how this translates

93
00:04:35,570 --> 00:04:39,763
to Kubernetes and how we work with Kubernetes and volumes.

