1 00:00:00,000 --> 00:00:04,300 [Intro Music] 2 00:00:04,350 --> 00:00:06,030 All right, I hope you were able to 3 00:00:06,030 --> 00:00:07,380 complete this challenge. And now 4 00:00:07,380 --> 00:00:09,540 let's do it together. And I'll first 5 00:00:09,540 --> 00:00:11,790 prepare commands in VS Code 6 00:00:11,790 --> 00:00:13,980 file. I have already created the 7 00:00:13,980 --> 00:00:15,900 folder called 'elasticsearch'; and 8 00:00:15,900 --> 00:00:17,520 here inside there is already a 9 00:00:17,760 --> 00:00:19,710 file called 'elasticsearch- 10 00:00:19,710 --> 00:00:21,510 commands.txt'; and you 11 00:00:21,510 --> 00:00:23,490 are able to find this file 12 00:00:23,490 --> 00:00:25,650 basically in GitHub repository, but 13 00:00:25,680 --> 00:00:27,870 we will use it in the next lecture. 14 00:00:28,080 --> 00:00:30,090 Now, I'll create a new file here in 15 00:00:30,090 --> 00:00:33,479 this folder named 'commands.txt', 16 00:00:33,660 --> 00:00:36,840 same as we did for wordpress and 17 00:00:36,870 --> 00:00:39,510 mysql examples, 'commands.txt'. 18 00:00:39,840 --> 00:00:41,280 And here first command will be 19 00:00:41,280 --> 00:00:43,260 creation of the custom network, 20 00:00:44,100 --> 00:00:49,620 CREATE NEW CUSTOM BRIDGE NETWORK. 21 00:00:50,400 --> 00:00:52,560 And I'll use here command 'docker 22 00:00:52,950 --> 00:00:56,700 network create', and name of this 23 00:00:56,700 --> 00:00:58,920 custom network will be 'elastic 24 00:01:00,210 --> 00:01:03,450 search', like this. Next, CREATE 25 00:01:03,720 --> 00:01:06,360 ELASTICSEARCH CONTAINER, ELASTIC 26 00:01:07,530 --> 00:01:11,970 SEARCH CONTAINER, like so. Here I'll 27 00:01:11,970 --> 00:01:15,450 use 'docker run' command, I'll use 28 00:01:15,450 --> 00:01:17,670 backslashes to separate different 29 00:01:17,940 --> 00:01:20,610 sub-parts of the same command. And 30 00:01:20,610 --> 00:01:22,800 next let me give name to this 31 00:01:22,800 --> 00:01:26,600 container, '--name elasticsearch', 32 00:01:26,600 --> 00:01:29,500 like so. Next, I have asked you 33 00:01:29,550 --> 00:01:31,740 to create port mapping, here will be 34 00:01:31,740 --> 00:01:33,780 '-p'; and external port will be 35 00:01:33,780 --> 00:01:39,180 9200 same as internal port 9200. 36 00:01:39,360 --> 00:01:42,090 I'll expose same port to outside. 37 00:01:42,570 --> 00:01:44,910 Next, let's specify here name of 38 00:01:44,910 --> 00:01:46,814 the image; and name will be 39 00:01:46,814 --> 00:01:51,420 'elasticsearch', like so. And also let's run 40 00:01:51,450 --> 00:01:53,760 this container in background. But 41 00:01:53,760 --> 00:01:55,680 it is optional. You could run it in 42 00:01:55,680 --> 00:01:57,750 foreground if you want. Also, 43 00:01:57,750 --> 00:01:59,850 we need to specify here custom 44 00:01:59,850 --> 00:02:02,040 network name, '--network', 45 00:02:02,490 --> 00:02:04,770 and name will be 'elasticsearch'. It 46 00:02:04,770 --> 00:02:06,660 is the name of this network we have 47 00:02:06,660 --> 00:02:09,090 created here above. And it seems 48 00:02:09,090 --> 00:02:11,880 that that's all what I asked you to 49 00:02:11,880 --> 00:02:14,610 do. All right, next container will 50 00:02:14,610 --> 00:02:18,570 be 'curl' container, CREATE CURL 51 00:02:18,750 --> 00:02:21,600 CONTAINER. And here we will use 52 00:02:21,600 --> 00:02:23,310 again, sorry, I have forgotten to 53 00:02:23,310 --> 00:02:25,770 add here backslashes, like so, 54 00:02:25,770 --> 00:02:28,440 backslash here, here and here. And 55 00:02:28,440 --> 00:02:30,120 here, let's create 'curl' 56 00:02:30,120 --> 00:02:33,300 container, 'docker run \', 57 00:02:33,750 --> 00:02:35,460 network will be the same. Let me 58 00:02:35,460 --> 00:02:38,280 copy this command from here, paste 59 00:02:38,280 --> 00:02:41,070 like so. Next, let's give it also 60 00:02:41,070 --> 00:02:44,670 name, '--name'; and name 61 00:02:44,700 --> 00:02:47,820 will be let's say 'curl' simply; 62 00:02:48,270 --> 00:02:51,990 and we will not expose any ports. And 63 00:02:51,990 --> 00:02:53,760 here next will be name of 64 00:02:53,760 --> 00:02:56,250 the image we want to use, and the 65 00:02:56,250 --> 00:02:58,530 name of the image is, let me go 66 00:02:58,530 --> 00:03:00,270 to history somewhere here, and let 67 00:03:00,270 --> 00:03:03,480 me copy image name from here. 68 00:03:03,900 --> 00:03:05,910 Okay, let me go back to VS Code, 69 00:03:05,910 --> 00:03:08,280 and let me paste the image name 70 00:03:08,280 --> 00:03:12,180 here, and I'll want to override 71 00:03:12,210 --> 00:03:16,080 default 'curl' command that is hard 72 00:03:16,080 --> 00:03:18,300 coded into this image, and I want 73 00:03:18,300 --> 00:03:20,670 to override it with 'sh' command or 74 00:03:20,670 --> 00:03:22,440 you're able to use 'bash' command as 75 00:03:22,440 --> 00:03:25,350 well, but I'll use 'sh' here like so. 76 00:03:25,920 --> 00:03:28,800 And it seems that that's all that we 77 00:03:28,800 --> 00:03:30,750 want to do in order to run those 78 00:03:30,750 --> 00:03:32,850 two containers. Let me quickly 79 00:03:32,850 --> 00:03:35,040 check. network is 'elasticsearch', here, 80 00:03:35,040 --> 00:03:37,620 here. And we create network here, 81 00:03:37,680 --> 00:03:40,500 we expose port here, and also we 82 00:03:40,500 --> 00:03:42,810 will be able to reach this 83 00:03:42,810 --> 00:03:44,760 container by its name, 84 00:03:44,790 --> 00:03:46,650 'elasticsearch'. That's actually the 85 00:03:46,650 --> 00:03:48,690 purpose why I have asked you to 86 00:03:48,690 --> 00:03:52,020 create separate custom network. All 87 00:03:52,020 --> 00:03:54,030 right, let me first create 88 00:03:54,060 --> 00:03:56,130 this custom network. Let me copy it 89 00:03:56,130 --> 00:03:58,500 and go to terminal, create new 90 00:03:58,500 --> 00:04:00,870 custom network, network was created, 91 00:04:00,900 --> 00:04:03,000 let me know run 'elasticsearch' 92 00:04:03,000 --> 00:04:04,890 container. At the moment I don't 93 00:04:04,890 --> 00:04:06,750 have 'elasticsearch' image in local 94 00:04:06,750 --> 00:04:08,880 cache, that's why first we need to 95 00:04:08,880 --> 00:04:10,710 pull it. But basically with 'docker 96 00:04:10,710 --> 00:04:12,450 run' command, we will first pull it, 97 00:04:12,450 --> 00:04:13,950 and afterwards immediately create 98 00:04:13,950 --> 00:04:15,960 container out of it. But actually 99 00:04:15,960 --> 00:04:17,430 let me quickly check the name of 100 00:04:17,430 --> 00:04:20,519 this image. Let me go to Docker Hub, 101 00:04:20,550 --> 00:04:23,459 and check whether name is correct. 102 00:04:23,700 --> 00:04:28,290 'elasticsearch' like so. And yes, 103 00:04:28,320 --> 00:04:29,520 image is correct. There is 104 00:04:29,520 --> 00:04:31,380 official Docker Image called 105 00:04:31,410 --> 00:04:33,930 'elasticsearch'; and there are more 106 00:04:33,930 --> 00:04:36,000 than 1 million downloads. Great. 107 00:04:36,120 --> 00:04:39,210 Let me go back to this file, let me 108 00:04:39,360 --> 00:04:42,240 copy this command, go to terminal, 109 00:04:42,570 --> 00:04:45,150 and let me launch 'elasticsearch' 110 00:04:45,150 --> 00:04:47,760 container here. Unable to find image 111 00:04:47,760 --> 00:04:50,610 locally. And there is an error 112 00:04:51,360 --> 00:04:53,250 'manifest for 'elasticsearch:latest 113 00:04:53,250 --> 00:04:55,320 not found:', let me check probably 114 00:04:55,320 --> 00:04:58,290 there is some error here. Let me go 115 00:04:58,290 --> 00:05:03,120 into this container, let me copy 116 00:05:03,120 --> 00:05:04,470 basically this command, and let me 117 00:05:04,470 --> 00:05:05,820 try to pull it first, 118 00:05:07,980 --> 00:05:10,920 'docker pull elasticsearch', and 119 00:05:10,920 --> 00:05:13,470 name is exactly the same as I have 120 00:05:13,470 --> 00:05:16,740 used here. Strange. Let me try to 121 00:05:16,740 --> 00:05:20,340 pull it like so. It seems that at the 122 00:05:20,340 --> 00:05:23,010 moment the tag 'latest', for some 123 00:05:23,010 --> 00:05:25,530 reason is not assigned to any image 124 00:05:25,590 --> 00:05:27,900 of 'elasticsearch' versions. And yes, 125 00:05:27,900 --> 00:05:29,940 that is the case. And we need to 126 00:05:29,940 --> 00:05:33,510 specify exact tag, either this one 127 00:05:33,540 --> 00:05:35,580 or this one. Let me use this tag, 128 00:05:35,610 --> 00:05:39,510 and let me modify command here. If 129 00:05:39,510 --> 00:05:40,950 you got the same error, please 130 00:05:40,950 --> 00:05:43,440 repeat this step along with me. So, 131 00:05:43,440 --> 00:05:45,870 let's pull a specific image of 132 00:05:45,870 --> 00:05:48,510 'elasticsearch'. Let me copy this 133 00:05:48,510 --> 00:05:50,070 command, save this file by the 134 00:05:50,070 --> 00:05:52,620 way, let me go back to terminal, and 135 00:05:52,650 --> 00:05:54,360 paste the copied command like so. 136 00:05:56,130 --> 00:05:57,720 Alright, now we are pulling image 137 00:05:57,720 --> 00:06:00,030 from Docker Hub. It is strange 138 00:06:00,060 --> 00:06:02,400 that 'latest' tag isn't available. I 139 00:06:02,400 --> 00:06:03,840 don't know why for some reason. 140 00:06:05,100 --> 00:06:07,110 Okay, image was finally downloaded, 141 00:06:07,170 --> 00:06:09,300 and the new container was created, 142 00:06:09,300 --> 00:06:11,940 and here I see SHA-1 hash of this 143 00:06:11,970 --> 00:06:14,040 newly created container. Let me 144 00:06:14,040 --> 00:06:15,960 verify whether it is running or not, 145 00:06:16,050 --> 00:06:18,540 'docker ps'; and yes, I see that 146 00:06:18,570 --> 00:06:20,310 'elasticsearch' container is now 147 00:06:20,310 --> 00:06:22,110 currently running. Here is the 148 00:06:22,110 --> 00:06:24,450 CONTAINER ID, here is IMAGE that 149 00:06:24,450 --> 00:06:26,310 was used, it is image with custom 150 00:06:26,310 --> 00:06:28,500 tag, and also you see here port 151 00:06:28,500 --> 00:06:30,300 mapping, we have exposed port 152 00:06:30,330 --> 00:06:34,260 9200 to outside, there was also 153 00:06:34,260 --> 00:06:36,120 another port that the Elasticsearch 154 00:06:36,150 --> 00:06:39,930 server listens to, it's 9300, but I 155 00:06:39,930 --> 00:06:41,850 didn't ask you to expose it because 156 00:06:41,850 --> 00:06:43,950 this port is usually used for 157 00:06:44,040 --> 00:06:45,510 internal communication between 158 00:06:45,510 --> 00:06:47,640 different Elasticsearch servers. At 159 00:06:47,640 --> 00:06:48,810 the moment, we have only one 160 00:06:48,810 --> 00:06:50,370 server. That's why there is no need 161 00:06:50,370 --> 00:06:52,620 to expose this port outside. 162 00:06:52,860 --> 00:06:54,840 Great. And here, I also see custom 163 00:06:54,870 --> 00:06:57,660 name for this container. Let me now 164 00:06:57,690 --> 00:07:00,330 start the 'curl' container. Let me 165 00:07:00,330 --> 00:07:03,420 go back to those commands. And I'll 166 00:07:03,450 --> 00:07:05,430 use this command. Let me copy it 167 00:07:05,430 --> 00:07:10,440 from here, go back to terminal, and 168 00:07:10,440 --> 00:07:13,110 paste it like so. Sorry, I have 169 00:07:13,110 --> 00:07:14,940 forgotten to add here '-it' 170 00:07:14,940 --> 00:07:17,430 options. All right. Let me try to 171 00:07:17,430 --> 00:07:23,576 add them here in this file, '-it', 172 00:07:23,576 --> 00:07:26,520 like so. Let me try to copy 173 00:07:26,520 --> 00:07:29,190 this command over again, paste it 174 00:07:29,190 --> 00:07:34,300 here, 'docker container prune', Yes. 175 00:07:34,300 --> 00:07:36,500 [no audio] 176 00:07:36,540 --> 00:07:39,720 Again, rerun this command. And now 177 00:07:39,720 --> 00:07:42,690 I'm in 'sh' shell. Let me open up 178 00:07:42,690 --> 00:07:44,250 web browser, and verify 179 00:07:44,250 --> 00:07:46,440 connection to 'elasticsearch'. Recap 180 00:07:46,440 --> 00:07:49,530 that we have exposed port 9200, 181 00:07:49,830 --> 00:07:52,334 and I'm able to use a localhost here, 182 00:07:53,900 --> 00:07:54,900 and port 183 00:07:56,400 --> 00:07:58,000 9200. 184 00:07:58,000 --> 00:08:00,000 [no audio] 185 00:08:00,000 --> 00:08:03,100 'This page isn't working'. Let me go back to 186 00:08:03,100 --> 00:08:05,400 terminal and verify again whether 187 00:08:05,400 --> 00:08:07,800 server is running. And it seems 188 00:08:07,800 --> 00:08:10,080 that it was exited. Let me verify 189 00:08:10,080 --> 00:08:15,600 logs for this container, 'docker logs elasticsearch', 190 00:08:15,600 --> 00:08:17,900 [no audio] 191 00:08:17,900 --> 00:08:18,900 there are some logs 192 00:08:18,960 --> 00:08:22,110 related to shutdown of the 193 00:08:22,920 --> 00:08:25,860 Elasticsearch server, "stopping...' 194 00:08:25,860 --> 00:08:28,100 [no audio] 195 00:08:28,110 --> 00:08:29,520 Actually, I don't know the reason 196 00:08:29,520 --> 00:08:31,740 why it stopped. Basically, let me 197 00:08:31,740 --> 00:08:35,650 quickly go to official page for 'elasticsearch' 198 00:08:35,650 --> 00:08:37,620 image, and check whether we 199 00:08:37,650 --> 00:08:41,580 started correctly or not. 'Run 200 00:08:41,580 --> 00:08:44,490 Elasticsearch'. Here is name, custom 201 00:08:44,490 --> 00:08:47,100 network, okay two ports exposed, but 202 00:08:47,100 --> 00:08:48,179 we basically don't needed the 203 00:08:48,179 --> 00:08:50,549 second port, and here we see 204 00:08:50,580 --> 00:08:52,200 additional environment variable 205 00:08:52,440 --> 00:08:55,799 "discovery.type=single-node". Probably 206 00:08:55,860 --> 00:08:57,990 that is the reason. Let me copy actually 207 00:08:57,990 --> 00:08:59,370 this environment variable setting, 208 00:08:59,400 --> 00:09:03,180 go to this command, and add it here 209 00:09:03,210 --> 00:09:05,430 like so, let me save the file, and 210 00:09:05,430 --> 00:09:07,290 now let me remove 'elasticsearch' 211 00:09:07,290 --> 00:09:09,150 container that is running, and let 212 00:09:09,150 --> 00:09:12,000 me start over new container. Let 213 00:09:12,000 --> 00:09:14,400 me clear terminal, 'docker rm 214 00:09:14,880 --> 00:09:17,880 elasticsearch', container was 215 00:09:17,880 --> 00:09:20,010 removed. Let me copy this command. 216 00:09:20,490 --> 00:09:22,740 Let me actually remove '-d' option 217 00:09:22,770 --> 00:09:24,570 and start the 'elasticsearch' 218 00:09:24,570 --> 00:09:26,880 container in foreground. Let me 219 00:09:26,880 --> 00:09:29,100 copy this command, go here, 220 00:09:29,100 --> 00:09:33,400 [no audio] 221 00:09:33,400 --> 00:09:38,500 alright, information about OpenJDK 222 00:09:38,970 --> 00:09:42,150 version. Elasticsearch actually 223 00:09:42,240 --> 00:09:45,210 requires Java Development Kit to be 224 00:09:45,210 --> 00:09:47,800 running in order to be able to start. 225 00:09:47,800 --> 00:09:50,100 [no audio] 226 00:09:50,130 --> 00:09:52,380 Some modules are being loaded right 227 00:09:52,380 --> 00:09:58,410 now. Here is version 7.6.2. Starting. 228 00:09:59,760 --> 00:10:03,180 Security disabled. Active 229 00:10:03,180 --> 00:10:05,550 license is now [BASIC]. Alright, it 230 00:10:05,550 --> 00:10:08,100 seems that now server is running. 231 00:10:08,460 --> 00:10:10,800 Let me go back to Chrome, and 232 00:10:10,950 --> 00:10:12,437 refresh page here. 233 00:10:14,070 --> 00:10:16,140 And now I get result. And it 234 00:10:16,140 --> 00:10:18,840 seems that the problem was in that 235 00:10:18,870 --> 00:10:20,460 custom environment variable, 236 00:10:20,460 --> 00:10:22,800 "discovery.type=single-node". All 237 00:10:22,800 --> 00:10:25,530 right, now we have Elasticsearch 238 00:10:25,530 --> 00:10:27,630 server running, and also we have 239 00:10:27,630 --> 00:10:30,630 'curl' container running. Let me go to 240 00:10:30,660 --> 00:10:33,180 'curl' container here, and let me 241 00:10:33,180 --> 00:10:35,340 try to ping elasticsearch 242 00:10:35,340 --> 00:10:39,150 container 'ping elasticsearch' like 243 00:10:39,150 --> 00:10:41,250 so. And I get result. And that 244 00:10:41,250 --> 00:10:43,380 means that we are now able to reach 245 00:10:43,440 --> 00:10:46,170 Elasticsearch server by its name, 246 00:10:46,200 --> 00:10:48,197 name of the container, elasticsearch; 247 00:10:48,197 --> 00:10:49,710 and here is IP address that 248 00:10:49,710 --> 00:10:51,300 was assigned to elasticsearch 249 00:10:51,300 --> 00:10:54,030 container. Great. Now we're all set, and 250 00:10:54,030 --> 00:10:56,220 next let's perform some actions 251 00:10:56,220 --> 00:10:58,650 with Elasticsearch Server. Let's 252 00:10:58,650 --> 00:11:00,570 create new index, and let's 253 00:11:00,600 --> 00:11:02,820 insert some documents in that index, 254 00:11:02,910 --> 00:11:04,500 and afterwards let's perform some 255 00:11:04,530 --> 00:11:06,730 searches. I will see you next. Bye-Bye. 256 00:11:06,730 --> 00:11:09,013 [no audio]