1
00:00:02,130 --> 00:00:04,370
So now that Docker is installed

2
00:00:04,370 --> 00:00:07,030
and up and running on that remote machine,

3
00:00:07,030 --> 00:00:11,900
we need to bring our local image onto that remote machine.

4
00:00:11,900 --> 00:00:15,380
And for this, we got two main approaches.

5
00:00:15,380 --> 00:00:19,890
Option number one, is that we deploy our source code.

6
00:00:19,890 --> 00:00:23,330
So, we find a way of copying our source code,

7
00:00:23,330 --> 00:00:25,640
so everything in this project folder,

8
00:00:25,640 --> 00:00:30,480
including the Dockerfile file onto that remote machine

9
00:00:30,480 --> 00:00:34,200
and then we build it there, we build the image there.

10
00:00:34,200 --> 00:00:38,320
The alternative is that we build the image ahead of time,

11
00:00:38,320 --> 00:00:40,400
for example, on our local machine.

12
00:00:40,400 --> 00:00:43,450
And we then just deploy that built image

13
00:00:43,450 --> 00:00:45,340
onto the remote machine.

14
00:00:45,340 --> 00:00:47,800
So, it's simply about building the image

15
00:00:47,800 --> 00:00:49,370
on the remote machine

16
00:00:49,370 --> 00:00:52,580
and doing that by pushing our source code there

17
00:00:52,580 --> 00:00:56,080
and running Docker build there and then Docker run,

18
00:00:56,080 --> 00:00:59,160
or if we want to build it locally, for example.

19
00:00:59,160 --> 00:01:02,450
And then just execute Docker run on the remote machine

20
00:01:02,450 --> 00:01:04,910
once we got the image there.

21
00:01:04,910 --> 00:01:07,280
And the first option

22
00:01:07,280 --> 00:01:11,620
has a lot of unnecessary complexity to it, to be honest.

23
00:01:11,620 --> 00:01:14,660
We need to do a lot of unnecessary work

24
00:01:14,660 --> 00:01:16,270
on the remote machine.

25
00:01:16,270 --> 00:01:18,760
Why would we build the image there?

26
00:01:18,760 --> 00:01:21,110
Which advantage does this give us?

27
00:01:21,110 --> 00:01:23,840
I'm not sure if it gives us any advantage.

28
00:01:23,840 --> 00:01:26,420
I'd rather prepare everything locally

29
00:01:26,420 --> 00:01:28,870
and have the finished image, locally,

30
00:01:28,870 --> 00:01:32,760
and then just get my finished image onto that remote host

31
00:01:32,760 --> 00:01:35,313
to then run it there as a container,

32
00:01:36,160 --> 00:01:39,350
and we can use Docker Hub for that.

33
00:01:39,350 --> 00:01:43,810
We can build our image locally, then push it to Docker Hub

34
00:01:43,810 --> 00:01:46,720
and then pull it from the remote server

35
00:01:46,720 --> 00:01:49,320
to then run it on the remote server.

36
00:01:49,320 --> 00:01:51,420
And that's exactly what we're going to do.

37
00:01:52,320 --> 00:01:56,163
So, for this, make sure that you do log into Docker Hub.

38
00:01:57,010 --> 00:01:59,700
We did set up an account early in the course already,

39
00:01:59,700 --> 00:02:03,050
and I did talk about Docker Hub there already.

40
00:02:03,050 --> 00:02:06,550
And then there, click create repository

41
00:02:06,550 --> 00:02:09,210
and create a new repository.

42
00:02:09,210 --> 00:02:12,130
And I'm going to name it, node-example-1

43
00:02:12,130 --> 00:02:13,443
but the name is up to you.

44
00:02:14,310 --> 00:02:17,510
So, I'm creating this new repository on Docker hub

45
00:02:17,510 --> 00:02:20,580
and I'll set it to be a public repository here

46
00:02:20,580 --> 00:02:22,850
since you only have a limited amount

47
00:02:22,850 --> 00:02:25,960
of private repositories if you're not paying.

48
00:02:25,960 --> 00:02:30,680
And simply click create, then...

49
00:02:30,680 --> 00:02:34,760
And now, we can push today's repository

50
00:02:34,760 --> 00:02:38,330
by creating an image, locally, on our machine,

51
00:02:38,330 --> 00:02:41,523
which has this repository name as a name.

52
00:02:42,530 --> 00:02:46,340
So, for that, I'm going to open up a new terminal,

53
00:02:46,340 --> 00:02:49,960
which is now not connected to my remote server.

54
00:02:49,960 --> 00:02:54,080
This first terminal still is connected via SSH.

55
00:02:54,080 --> 00:02:56,180
This terminal here isn't.

56
00:02:56,180 --> 00:02:59,700
And you can tell by the way this input starts.

57
00:02:59,700 --> 00:03:02,700
If it says ec2-user@ something,

58
00:03:02,700 --> 00:03:05,120
or if it doesn't say that.

59
00:03:05,120 --> 00:03:07,460
And then on my local terminal,

60
00:03:07,460 --> 00:03:10,440
I'm going to build this image here.

61
00:03:10,440 --> 00:03:12,100
And actually, before I do that,

62
00:03:12,100 --> 00:03:14,620
I'm going to add a .dockerignore file,

63
00:03:14,620 --> 00:03:17,150
and I'm going to ignore node modules

64
00:03:17,150 --> 00:03:18,610
if we would have it here,

65
00:03:18,610 --> 00:03:23,380
ignore the Dockerfile and ignore any .pem files

66
00:03:23,380 --> 00:03:26,170
to not put this key into my image.

67
00:03:26,170 --> 00:03:29,470
I don't want to share it with anyone, so I will ignore it

68
00:03:29,470 --> 00:03:34,363
so that this key file is not getting added to my image.

69
00:03:35,570 --> 00:03:39,330
And with that created, we can now run Docker build dot.

70
00:03:39,330 --> 00:03:43,940
Give this a tag of node-dep-example-1, for example,

71
00:03:43,940 --> 00:03:45,103
and hit enter.

72
00:03:46,060 --> 00:03:48,150
And now this image is built

73
00:03:48,150 --> 00:03:50,623
and we now have this image locally.

74
00:03:51,890 --> 00:03:55,280
Now, as I explained earlier in the course already,

75
00:03:55,280 --> 00:04:00,280
we can now push this image to Docker Hub by renaming it.

76
00:04:00,960 --> 00:04:04,140
And we can do this with the Docker tag command.

77
00:04:04,140 --> 00:04:09,140
And here, I want to give a new tag to this image here,

78
00:04:09,310 --> 00:04:12,033
the node-dep-example-1 image.

79
00:04:13,200 --> 00:04:16,810
So, we can run Docker tag and then use this image name

80
00:04:16,810 --> 00:04:21,779
and then use, in my case, academind/node-example-1

81
00:04:21,779 --> 00:04:25,677
as a new name with or without a tag.

82
00:04:25,677 --> 00:04:29,560
The tag is optional, so I will just focus on the name here.

83
00:04:29,560 --> 00:04:34,560
And of course, you should use your repository name here.

84
00:04:34,570 --> 00:04:36,080
So, for me, it's this one

85
00:04:38,290 --> 00:04:40,270
and enter this here.

86
00:04:40,270 --> 00:04:42,980
And now if we list all images again,

87
00:04:42,980 --> 00:04:46,620
we see we have our old image,

88
00:04:46,620 --> 00:04:50,193
but also the same image with a different name now.

89
00:04:51,520 --> 00:04:56,220
And this allows us to then run Docker push

90
00:04:56,220 --> 00:04:59,010
with that tag or with that name,

91
00:04:59,010 --> 00:05:01,220
and this image will be pushed.

92
00:05:01,220 --> 00:05:04,540
However, this will fail if you're not logged in.

93
00:05:04,540 --> 00:05:06,550
So, let's log in first

94
00:05:06,550 --> 00:05:09,563
with your Docker Hub username and password.

95
00:05:11,990 --> 00:05:14,780
And once you did log in successfully,

96
00:05:14,780 --> 00:05:17,310
you can run this Docker push command.

97
00:05:17,310 --> 00:05:22,310
And now, this locally built image is pushed to Docker hub.

98
00:05:23,020 --> 00:05:24,630
And that means that now,

99
00:05:24,630 --> 00:05:28,340
the image building process is already finished

100
00:05:28,340 --> 00:05:30,330
and on our remote machine,

101
00:05:30,330 --> 00:05:32,193
we now just need to run it.

