1 00:00:00,000 --> 00:00:04,200 [Intro Music] 2 00:00:04,230 --> 00:00:06,723 All right, we have just pulled 'node' 3 00:00:06,723 --> 00:00:08,550 image from Docker Hub; and we 4 00:00:08,550 --> 00:00:10,560 have created first a Node.js 5 00:00:10,560 --> 00:00:12,540 container, and we have basically 6 00:00:12,540 --> 00:00:14,940 executed some commands like console. 7 00:00:14,940 --> 00:00:17,100 log, or assignment of the value to 8 00:00:17,100 --> 00:00:18,480 the variable inside of the 9 00:00:18,480 --> 00:00:21,540 interactive interpreter of Node.js 10 00:00:21,540 --> 00:00:23,550 inside of the container. And now 11 00:00:23,550 --> 00:00:25,710 let's create the sample Node.js 12 00:00:25,710 --> 00:00:27,660 application as we did with Python, 13 00:00:27,840 --> 00:00:29,280 and let's do that on our local 14 00:00:29,280 --> 00:00:31,230 computer, and afterwards, let's run 15 00:00:31,230 --> 00:00:33,870 it using Node.js container. Let me 16 00:00:33,870 --> 00:00:36,000 clear terminal and go to Visual 17 00:00:36,000 --> 00:00:37,890 Studio Code, and create here, 18 00:00:38,130 --> 00:00:40,740 new folder near folders 'nginx', 19 00:00:40,740 --> 00:00:43,500 'python', and so on. Let's close any 20 00:00:43,560 --> 00:00:46,230 related to previous projects files. 21 00:00:46,350 --> 00:00:48,360 And here let's create a new folder, 22 00:00:48,360 --> 00:00:51,360 and let's name it 'node', like so. 23 00:00:51,480 --> 00:00:53,130 And here inside of this folder, 24 00:00:53,130 --> 00:00:55,590 let's create a new file, simply 25 00:00:55,590 --> 00:00:58,590 hello.js, like this. And here in 26 00:00:58,590 --> 00:01:00,450 this file, let's simply type 27 00:01:00,450 --> 00:01:03,870 console.log('This application 28 00:01:03,870 --> 00:01:09,700 was executed by Node.js container')', 29 00:01:09,720 --> 00:01:12,750 like so. Let's save this. And also 30 00:01:12,750 --> 00:01:14,820 you're able to wrap long lines 31 00:01:14,850 --> 00:01:17,190 using key combination 'Alt' + option 32 00:01:17,220 --> 00:01:19,590 'z', like so. And let me hide this 33 00:01:19,590 --> 00:01:21,270 left pane and we are actually ready 34 00:01:21,270 --> 00:01:23,220 to go and we are ready to execute 35 00:01:23,250 --> 00:01:25,860 this tiny application inside of the 36 00:01:25,860 --> 00:01:28,650 single file hello.js using Node 37 00:01:28,650 --> 00:01:31,080 container. Let's go to terminal and 38 00:01:31,110 --> 00:01:32,640 of course, you may guess that we 39 00:01:32,640 --> 00:01:35,100 need to use here volume mapping 40 00:01:35,130 --> 00:01:37,260 in order to map our volume on our 41 00:01:37,260 --> 00:01:39,540 local computer to a specific folder 42 00:01:39,570 --> 00:01:41,370 inside of the container that will 43 00:01:41,370 --> 00:01:43,830 be running Node.js. Let's do so. 44 00:01:44,010 --> 00:01:46,380 Let's first 'cd' to 'node' folder, 45 00:01:46,380 --> 00:01:47,850 because we will use the same as 46 00:01:47,850 --> 00:01:50,430 before, variable 'PWD'; and that's why 47 00:01:50,430 --> 00:01:52,470 we need to be inside of the folder 48 00:01:52,500 --> 00:01:54,960 that has files that we need to map 49 00:01:55,200 --> 00:01:57,840 to container. Let's 'cd' to 'node', and 50 00:01:57,840 --> 00:02:00,240 here let's run container, 'docker 51 00:02:00,720 --> 00:02:03,870 run -v', we will use a volume mapping, 52 00:02:03,870 --> 00:02:08,370 '$PWD', next ':', and let's map 53 00:02:08,370 --> 00:02:11,310 this local folder to '/app' folder, 54 00:02:11,340 --> 00:02:12,900 same as we did in Python 55 00:02:12,900 --> 00:02:14,580 application. And of course, let's 56 00:02:14,580 --> 00:02:16,110 specify here working directory 57 00:02:16,140 --> 00:02:18,120 inside of the node container using 58 00:02:18,150 --> 00:02:19,680 '-w' option, and here 59 00:02:19,680 --> 00:02:22,920 let's type '/app', like so. And 60 00:02:22,920 --> 00:02:26,280 next comes 'node', it is name of the 61 00:02:26,310 --> 00:02:28,050 image that we will use for creation 62 00:02:28,080 --> 00:02:30,000 of this container. And afterwards, 63 00:02:30,030 --> 00:02:32,220 let's override the default command, 64 00:02:32,280 --> 00:02:33,750 that is actually 'node' command, 65 00:02:33,870 --> 00:02:36,300 using 'node', plus name of the file 66 00:02:36,330 --> 00:02:38,310 that we want to execute inside of 67 00:02:38,310 --> 00:02:40,080 the container. And for that, let's 68 00:02:40,080 --> 00:02:42,660 simply type 'node'', and next comes 69 00:02:42,690 --> 00:02:44,850 name of the file, and name of our 70 00:02:44,850 --> 00:02:47,430 file is 'hello.js'. Let's here 71 00:02:47,430 --> 00:02:50,040 type 'hello.js'. And please note 72 00:02:50,040 --> 00:02:52,080 that here is command that will be 73 00:02:52,110 --> 00:02:54,060 executed upon creation of the 74 00:02:54,060 --> 00:02:56,400 container. Here's name of the 75 00:02:56,400 --> 00:02:58,860 image. Great. Let's press Enter, and 76 00:02:58,860 --> 00:03:02,430 see what will happen. And I see 77 00:03:02,430 --> 00:03:04,020 result, 'This application was 78 00:03:04,050 --> 00:03:06,810 executed by Node.js container'; and 79 00:03:06,810 --> 00:03:09,663 that means that our script, hello.js 80 00:03:09,663 --> 00:03:12,150 was successfully executed by 81 00:03:12,210 --> 00:03:14,880 Node.js container. But after 82 00:03:14,910 --> 00:03:16,830 execution of the script, process, 83 00:03:16,860 --> 00:03:18,870 'node' process was terminated; and 84 00:03:18,870 --> 00:03:20,790 container was stopped. We could 85 00:03:20,790 --> 00:03:22,710 verify that as usually using 'docker 86 00:03:22,740 --> 00:03:25,050 ps' command. There are no containers 87 00:03:25,080 --> 00:03:26,700 at the moment. This is how you're 88 00:03:26,700 --> 00:03:28,680 able to run a very simple 89 00:03:28,680 --> 00:03:30,810 application using Node.js 90 00:03:30,810 --> 00:03:33,300 container. And notice that we were 91 00:03:33,300 --> 00:03:35,250 not required to create port mapping 92 00:03:35,280 --> 00:03:36,960 because this application doesn't 93 00:03:36,960 --> 00:03:39,660 require any external ports. But if 94 00:03:39,660 --> 00:03:42,030 you create any for example API 95 00:03:42,060 --> 00:03:44,340 using Node.js, then you probably need 96 00:03:44,340 --> 00:03:45,870 to open some ports in order to 97 00:03:45,870 --> 00:03:48,960 access endpoints, API endpoints from 98 00:03:48,990 --> 00:03:51,840 external clients. Great. This is how 99 00:03:51,840 --> 00:03:53,610 we are able to run very simple 100 00:03:53,610 --> 00:03:55,650 application using Node.js But please 101 00:03:55,650 --> 00:03:57,510 note that things may become more 102 00:03:57,510 --> 00:03:59,640 complicated if you want to install 103 00:03:59,670 --> 00:04:02,250 some additional dependencies using 104 00:04:02,280 --> 00:04:05,370 npm. Let's try to create a bit more 105 00:04:05,370 --> 00:04:07,530 complicated Node.js application that 106 00:04:07,530 --> 00:04:09,840 will require some additional NPM 107 00:04:09,840 --> 00:04:12,100 modules. Let's do that next. Bye-Bye. 108 00:04:12,100 --> 00:04:14,400 [no audio]