1
00:00:02,370 --> 00:00:04,150
Now it's just a first example,

2
00:00:04,150 --> 00:00:06,750
there is more you can and should find

3
00:00:06,750 --> 00:00:10,200
if you really would want to have this up and running,

4
00:00:10,200 --> 00:00:13,040
for example, connect your own custom domain.

5
00:00:13,040 --> 00:00:13,940
But as I said,

6
00:00:13,940 --> 00:00:16,250
that is something you can do with help

7
00:00:16,250 --> 00:00:18,520
of the official AWS docs,

8
00:00:18,520 --> 00:00:20,960
because this will not be the final way

9
00:00:20,960 --> 00:00:23,300
of deploying something we'll have a look at

10
00:00:23,300 --> 00:00:24,620
in this module.

11
00:00:24,620 --> 00:00:27,550
Because you might have more complex applications

12
00:00:27,550 --> 00:00:32,549
and also different needs for your deployment process.

13
00:00:32,860 --> 00:00:35,150
Still it's a first example,

14
00:00:35,150 --> 00:00:37,800
and it is our application up and running

15
00:00:37,800 --> 00:00:42,050
and you therefore hopefully see why Docker is awesome

16
00:00:42,050 --> 00:00:44,390
and how it can help us during development,

17
00:00:44,390 --> 00:00:47,270
but then also for deployment.

18
00:00:47,270 --> 00:00:49,650
Now still to finish up this example,

19
00:00:49,650 --> 00:00:53,830
let me show you how you could push updates to your code,

20
00:00:53,830 --> 00:00:57,040
to that remote server and how you can then stop

21
00:00:57,040 --> 00:01:00,610
and shut everything down if you want that to do that.

22
00:01:00,610 --> 00:01:03,570
So let's start with updating the code.

23
00:01:03,570 --> 00:01:05,640
I'll make a very simple change here.

24
00:01:05,640 --> 00:01:08,180
I add a bunch of exclamation marks here

25
00:01:08,180 --> 00:01:11,583
in the welcome HTML file after this works.

26
00:01:12,820 --> 00:01:16,650
Now, of course this change is not automatically reflected

27
00:01:16,650 --> 00:01:18,500
on the remote server.

28
00:01:18,500 --> 00:01:20,750
There we still see the old version

29
00:01:20,750 --> 00:01:24,030
because I only made that change locally.

30
00:01:24,030 --> 00:01:26,440
Now, the process of bringing these updates

31
00:01:26,440 --> 00:01:29,160
to the remote server is simple, though.

32
00:01:29,160 --> 00:01:32,830
We rebuild the image push it to Docker Hub again,

33
00:01:32,830 --> 00:01:35,450
and make sure we use this updated image

34
00:01:35,450 --> 00:01:36,893
on the remote server.

35
00:01:38,170 --> 00:01:41,460
So therefore here on my local machine,

36
00:01:41,460 --> 00:01:44,490
in the terminal, running on my local machine,

37
00:01:44,490 --> 00:01:48,653
I rebuild my node-dep-example-1 image,

38
00:01:49,560 --> 00:01:53,100
which now takes into a updated source code.

39
00:01:53,100 --> 00:01:55,640
I then tag it appropriately.

40
00:01:55,640 --> 00:01:58,950
And then we, again push this now updated image

41
00:01:58,950 --> 00:02:01,200
to Docker Hub.

42
00:02:01,200 --> 00:02:04,540
And you see it's pushing this in a very efficient way,

43
00:02:04,540 --> 00:02:07,030
only pushing the parts that really changed

44
00:02:07,030 --> 00:02:10,050
and reusing the layers that didn't change.

45
00:02:10,050 --> 00:02:12,770
Now, once we did that, we can switch to the terminal,

46
00:02:12,770 --> 00:02:15,950
which is connected to the EC2 instance.

47
00:02:15,950 --> 00:02:18,330
And there I will first of all,

48
00:02:18,330 --> 00:02:20,430
list all running containers

49
00:02:20,430 --> 00:02:24,730
and then stop this container which we started before

50
00:02:24,730 --> 00:02:28,780
with sudo docker stop and then the container name.

51
00:02:28,780 --> 00:02:32,450
So now this stops this container on the remote machine,

52
00:02:32,450 --> 00:02:36,770
and then we wanna rerun it based on this updated image.

53
00:02:36,770 --> 00:02:38,810
So therefore once it's stopped,

54
00:02:38,810 --> 00:02:42,013
we can repeat this sudo docker run command,

55
00:02:42,970 --> 00:02:45,860
but you will notice that if we do that in reload,

56
00:02:45,860 --> 00:02:48,330
we still see the old version.

57
00:02:48,330 --> 00:02:50,040
The reason for that is that

58
00:02:50,040 --> 00:02:54,860
whenever you docker run an image, Docker always just checks,

59
00:02:54,860 --> 00:02:57,840
whether it already has this image locally.

60
00:02:57,840 --> 00:03:00,550
And if it does it just uses that.

61
00:03:00,550 --> 00:03:02,080
It does not check,

62
00:03:02,080 --> 00:03:05,660
if there is a more up-to-date remote image available.

63
00:03:05,660 --> 00:03:08,460
To ensure that we do use the latest version though,

64
00:03:08,460 --> 00:03:11,100
we can run docker pull manually

65
00:03:11,100 --> 00:03:13,830
and simply pull this image again.

66
00:03:13,830 --> 00:03:16,030
This will now pull the latest version

67
00:03:16,030 --> 00:03:18,730
and therefore our updated version.

68
00:03:18,730 --> 00:03:20,620
And once we did this,

69
00:03:20,620 --> 00:03:24,080
we can shut down this container we just started,

70
00:03:24,080 --> 00:03:26,500
which still uses the old version.

71
00:03:26,500 --> 00:03:30,380
But now that we pulled the latest version with docker pull,

72
00:03:30,380 --> 00:03:32,570
when we run docker run the next time,

73
00:03:32,570 --> 00:03:35,210
this latest version will be used.

74
00:03:35,210 --> 00:03:39,620
So once this stopped, we can now run docker run again.

75
00:03:39,620 --> 00:03:42,500
And because we pulled the latest version manually,

76
00:03:42,500 --> 00:03:45,300
now that latest version is up and running.

77
00:03:45,300 --> 00:03:46,770
And hence, if I reload here,

78
00:03:46,770 --> 00:03:48,923
I see all the exclamation marks.

79
00:03:49,900 --> 00:03:53,570
And that is how you could update your deployed code.

80
00:03:53,570 --> 00:03:55,440
By simply rebuilding the image,

81
00:03:55,440 --> 00:03:59,203
pushing it again, pulling, and then rerunning the container.

82
00:04:01,080 --> 00:04:03,570
Now, if you ever want to shut everything down

83
00:04:03,570 --> 00:04:08,250
or you temporarily wanna pause this instance here,

84
00:04:08,250 --> 00:04:13,250
you can of course use docker stop to stop your container.

85
00:04:13,570 --> 00:04:16,190
And if we do this,

86
00:04:16,190 --> 00:04:19,000
for this container we just started again,

87
00:04:19,000 --> 00:04:23,510
you will of course see that once this is stopped,

88
00:04:23,510 --> 00:04:24,643
which it is now.

89
00:04:26,450 --> 00:04:28,690
Reloading this webpage will fail

90
00:04:28,690 --> 00:04:31,220
because there is no running web server

91
00:04:31,220 --> 00:04:33,000
on this EC2 instance anymore.

92
00:04:33,000 --> 00:04:34,593
Because we just stopped it.

93
00:04:35,730 --> 00:04:39,170
Now you can always restarted with docker run again,

94
00:04:39,170 --> 00:04:41,610
or if you wouldn't remove stop containers

95
00:04:41,610 --> 00:04:43,760
all with docker start.

96
00:04:43,760 --> 00:04:46,650
But if you wanna shut down your EC2 instance forever,

97
00:04:46,650 --> 00:04:50,180
you can do this from inside the EC2 dashboard.

98
00:04:50,180 --> 00:04:51,993
There under instances,

99
00:04:53,080 --> 00:04:55,410
simply make sure you select the instance

100
00:04:55,410 --> 00:04:58,790
which is running your remote dockerized application

101
00:04:58,790 --> 00:05:03,490
and under actions, choose Instance State, Terminate.

102
00:05:03,490 --> 00:05:06,210
And this now really deletes the entire instance

103
00:05:06,210 --> 00:05:08,500
and the application running on it.

104
00:05:08,500 --> 00:05:12,510
And I'll do this here because this was a nice first example

105
00:05:12,510 --> 00:05:16,030
and a possible way of deploying a Docker application.

106
00:05:16,030 --> 00:05:17,940
But it will not be the final way

107
00:05:17,940 --> 00:05:20,440
of deploying an application with Docker.

108
00:05:20,440 --> 00:05:23,350
Because it turns out that this approach,

109
00:05:23,350 --> 00:05:25,690
which has showed you in great detail here,

110
00:05:25,690 --> 00:05:29,583
has a couple of disadvantages and downsides.

