1 00:00:00,000 --> 00:00:04,200 [Intro Music] 2 00:00:04,290 --> 00:00:06,180 Alright guys, we have just explored 3 00:00:06,180 --> 00:00:07,830 the python container, and we have 4 00:00:07,830 --> 00:00:10,260 created a couple of sample Python 5 00:00:10,260 --> 00:00:12,030 applications. And now it's a good 6 00:00:12,030 --> 00:00:14,250 time to move on. And now let's try 7 00:00:14,340 --> 00:00:16,500 and run another container Node.js 8 00:00:16,500 --> 00:00:19,140 container. And let me first show 9 00:00:19,140 --> 00:00:20,850 you that at the moment, we don't 10 00:00:20,850 --> 00:00:22,590 have Node.js installed on this 11 00:00:22,590 --> 00:00:24,720 computer. If I'll type 'node 12 00:00:24,720 --> 00:00:26,490 -v', I'll see, 'command not 13 00:00:26,490 --> 00:00:29,200 found: node'. And that means that Node.js 14 00:00:29,200 --> 00:00:31,500 along with NPM actually are not 15 00:00:31,590 --> 00:00:33,930 installed on this computer. Now, 16 00:00:33,930 --> 00:00:35,580 let's suppose that you want to 17 00:00:35,580 --> 00:00:37,830 create the Node.js application and 18 00:00:37,860 --> 00:00:40,290 run it using node. But you don't 19 00:00:40,290 --> 00:00:42,060 want to install node on your 20 00:00:42,060 --> 00:00:44,460 computer. Or, for example, you want 21 00:00:44,490 --> 00:00:46,380 to run your application using a 22 00:00:46,410 --> 00:00:48,750 specific version of node that 23 00:00:48,750 --> 00:00:50,370 differs from the version that is 24 00:00:50,370 --> 00:00:52,470 installed on your computer. In 25 00:00:52,560 --> 00:00:54,450 such case Docker will help you. 26 00:00:55,140 --> 00:00:57,180 Let's now create Node.js 27 00:00:57,180 --> 00:00:59,310 container, and first let's pull Node. 28 00:00:59,310 --> 00:01:01,830 js image from Docker Hub. And let's 29 00:01:01,830 --> 00:01:03,660 create a very simple Node.js 30 00:01:03,660 --> 00:01:05,310 application that will print simply 31 00:01:05,310 --> 00:01:07,080 'Hello from Node.js application' to 32 00:01:07,080 --> 00:01:09,150 the terminal. Let's do that. Let's 33 00:01:09,150 --> 00:01:10,620 clear terminal. And let me 34 00:01:10,620 --> 00:01:12,780 first look at containers that 35 00:01:12,780 --> 00:01:14,310 are currently running. There are no 36 00:01:14,310 --> 00:01:16,380 such containers. But if I have a 37 00:01:16,380 --> 00:01:18,330 look at history, I will see a bunch 38 00:01:18,330 --> 00:01:20,340 of python containers. And let me 39 00:01:20,340 --> 00:01:22,530 prune them quickly. And for that we 40 00:01:22,530 --> 00:01:25,110 could use command 'docker container 41 00:01:25,380 --> 00:01:28,110 prune', like so. And all containers, 42 00:01:28,140 --> 00:01:30,570 stopped containers will be deleted. 43 00:01:32,100 --> 00:01:34,800 'docker ps -a', and now I see that 44 00:01:34,860 --> 00:01:37,020 there are no stopped containers. And 45 00:01:37,020 --> 00:01:38,760 notice that we have reclaimed 46 00:01:38,790 --> 00:01:41,400 around 10 megabytes of disk space 47 00:01:41,520 --> 00:01:44,280 that was utilized by those stopped 48 00:01:44,280 --> 00:01:46,710 containers. Great. Let me now clear 49 00:01:46,710 --> 00:01:48,570 terminal. And now let's pull Node. 50 00:01:48,570 --> 00:01:50,850 js image. And lets use first layer 51 00:01:50,850 --> 00:01:53,190 stack it is default one. 'docker 52 00:01:53,550 --> 00:01:57,780 pull node', Enter, 'Pulling from 53 00:01:57,780 --> 00:02:00,030 library/node'. And you see that this 54 00:02:00,060 --> 00:02:02,850 image has multiple 'fs' layers. Let's 55 00:02:02,850 --> 00:02:04,560 wait a bit until download and 56 00:02:04,560 --> 00:02:06,150 extraction will be completed. 57 00:02:06,450 --> 00:02:07,740 Meanwhile, let me tell you a few 58 00:02:07,740 --> 00:02:09,600 words about Node. Node.js is 59 00:02:09,600 --> 00:02:11,850 basically backend JavaScript 60 00:02:11,880 --> 00:02:13,410 framework that allows you pretty 61 00:02:13,410 --> 00:02:15,180 easily and faster create any 62 00:02:15,180 --> 00:02:17,070 JavaScript backend applications. 63 00:02:17,250 --> 00:02:19,170 And you're able, for example, create 64 00:02:19,200 --> 00:02:22,230 API using JavaScript and run it on 65 00:02:22,230 --> 00:02:24,000 your backend servers, or you could 66 00:02:24,000 --> 00:02:25,890 perform any operations with file 67 00:02:25,890 --> 00:02:27,930 system. And in this course, we will 68 00:02:27,930 --> 00:02:29,460 try to create a sample 69 00:02:29,460 --> 00:02:30,690 application that will create the 70 00:02:30,690 --> 00:02:32,910 new files in your working directory 71 00:02:32,940 --> 00:02:35,220 and so on. So that's Node.js. And 72 00:02:35,220 --> 00:02:36,960 usually it is used in conjunction 73 00:02:37,140 --> 00:02:39,210 with frontend JavaScript 74 00:02:39,210 --> 00:02:41,340 frameworks like React or Vue or 75 00:02:41,340 --> 00:02:43,680 Angular, and you're able to create 76 00:02:43,680 --> 00:02:45,390 the JavaScript microservices 77 00:02:45,420 --> 00:02:47,430 on frontend and on backend, that 78 00:02:47,460 --> 00:02:49,440 simplifies actually, entire 79 00:02:49,440 --> 00:02:51,870 development workflow. Okay, pull 80 00:02:51,900 --> 00:02:53,910 and extraction were completed, and 81 00:02:53,910 --> 00:02:56,700 now we have node image locally in 82 00:02:56,700 --> 00:02:58,860 our cache, and we could verify that 83 00:02:58,920 --> 00:03:02,010 'docker images'. And yes, here is 84 00:03:02,070 --> 00:03:04,290 node in this list. And you see that 85 00:03:04,290 --> 00:03:06,480 its size is approximately the same 86 00:03:06,510 --> 00:03:09,210 as size of python image. Here you 87 00:03:09,210 --> 00:03:11,460 see those sizes and both of them 88 00:03:11,490 --> 00:03:13,500 are around one gigabyte in size. 89 00:03:13,710 --> 00:03:15,810 Great. Let's now create the Node.js 90 00:03:15,810 --> 00:03:17,850 container and let's simply create it 91 00:03:17,850 --> 00:03:19,920 first using the 'docker run node' 92 00:03:19,920 --> 00:03:22,770 command, like so. 'docker run node', 93 00:03:23,970 --> 00:03:26,040 container was created, process was 94 00:03:26,040 --> 00:03:27,450 terminated, and container was 95 00:03:27,450 --> 00:03:29,670 stopped as well, as usually. 'docker 96 00:03:29,670 --> 00:03:31,650 ps', there are no containers 97 00:03:31,680 --> 00:03:33,630 running. Let's now run this 98 00:03:33,630 --> 00:03:35,610 container in interactive mode with 99 00:03:35,640 --> 00:03:38,910 options '-i' and '-t'. 'docker 100 00:03:39,450 --> 00:03:44,820 run -it node'. And now I see 101 00:03:44,820 --> 00:03:48,875 prompt, 'Welcome to Node.js v13.13.0'. 102 00:03:48,875 --> 00:03:49,710 And in your case, you 103 00:03:49,710 --> 00:03:51,450 may see another version, because 104 00:03:51,480 --> 00:03:53,520 tag 'latest' may be assigned to 105 00:03:53,550 --> 00:03:55,410 different images at different 106 00:03:55,410 --> 00:03:57,390 moments of time. For example, when 107 00:03:57,420 --> 00:03:59,310 there is a new stable version of 108 00:03:59,340 --> 00:04:01,800 image is released, then tag 'latest' 109 00:04:01,830 --> 00:04:03,690 is assigned to that new version. 110 00:04:04,020 --> 00:04:06,060 Great, you are able to type for 111 00:04:06,060 --> 00:04:09,120 example, 'help' here, '.help', and 112 00:04:09,120 --> 00:04:10,830 you'll see some basic commands that 113 00:04:10,830 --> 00:04:12,480 you are able to utilize in this 114 00:04:12,480 --> 00:04:14,580 Node.js interpreter, because we are 115 00:04:14,580 --> 00:04:16,500 actually connected now to Node.js 116 00:04:16,500 --> 00:04:18,420 interpreter. And we are able to 117 00:04:18,420 --> 00:04:20,279 execute some JavaScript commands 118 00:04:20,399 --> 00:04:22,470 directly here. For example, let's 119 00:04:22,470 --> 00:04:26,430 type console.log('Hello from Node. 120 00:04:26,490 --> 00:04:29,910 js container')', like so, press Enter. 121 00:04:30,030 --> 00:04:31,920 And you see 'Hello from Node.js 122 00:04:31,920 --> 00:04:34,230 container' here in terminal. Great. 123 00:04:34,350 --> 00:04:36,240 That's how we were able to connect 124 00:04:36,270 --> 00:04:38,550 to interactive shell inside of 125 00:04:38,550 --> 00:04:40,470 the Node.js container where you're 126 00:04:40,470 --> 00:04:42,390 able to execute any JavaScript 127 00:04:42,390 --> 00:04:43,680 commands, or you could type for 128 00:04:43,680 --> 00:04:46,170 example 10 + 5, and you should 129 00:04:46,170 --> 00:04:48,360 get 15 here in the terminal, or you 130 00:04:48,360 --> 00:04:49,590 could create a new variable, for 131 00:04:49,590 --> 00:04:51,240 example, let's create variable 'a' and 132 00:04:51,240 --> 00:04:53,460 assign the value to it, 10, and 133 00:04:53,460 --> 00:04:55,140 here we are able to access variable 134 00:04:55,140 --> 00:04:57,360 10 and in such case you will see 135 00:04:57,390 --> 00:04:59,160 its value here in the terminal. 136 00:04:59,340 --> 00:05:01,410 Great. Are you able to interact with 137 00:05:01,440 --> 00:05:02,400 Node.js 138 00:05:02,430 --> 00:05:04,350 interpreter? Let's go out of it. 139 00:05:04,350 --> 00:05:06,616 And actually you need to type a '.exit' 140 00:05:06,616 --> 00:05:07,710 in order to exit from this 141 00:05:07,710 --> 00:05:09,780 interactive shell like so. Process 142 00:05:09,780 --> 00:05:11,670 was terminated, and now container 143 00:05:11,670 --> 00:05:13,680 was stopped. 'docker ps', there are no 144 00:05:13,680 --> 00:05:15,960 containers running. Great. Let's 145 00:05:15,960 --> 00:05:18,180 next create the sample Node.js 146 00:05:18,180 --> 00:05:20,490 application, and run it using Node. 147 00:05:20,490 --> 00:05:22,957 js container. Let's do that next. Bye-Bye. 148 00:05:22,957 --> 00:05:24,800 [no audio]