1 00:00:00,000 --> 00:00:04,099 [Intro Music] 2 00:00:04,170 --> 00:00:06,150 All right, I have just rearranged 3 00:00:06,180 --> 00:00:08,070 those two windows and stacked on 4 00:00:08,070 --> 00:00:10,110 top of each other in order to be 5 00:00:10,110 --> 00:00:11,970 able to leave my face here in this 6 00:00:11,970 --> 00:00:13,680 corner. So let's proceed. And in 7 00:00:13,680 --> 00:00:16,200 this lecture, let's create the two 8 00:00:16,200 --> 00:00:18,870 different containers based on nginx 9 00:00:18,900 --> 00:00:21,360 image. And for that we will serve 10 00:00:21,360 --> 00:00:23,700 files from different folders. Let's 11 00:00:23,700 --> 00:00:25,920 get right into it. Let's go to 12 00:00:25,920 --> 00:00:27,690 Visual Studio Code, and recap that 13 00:00:27,720 --> 00:00:29,970 there was 'containers' folder on 14 00:00:29,970 --> 00:00:31,920 Desktop; and inside of it, there 15 00:00:31,920 --> 00:00:34,200 was nginx folder. And we have used 16 00:00:34,230 --> 00:00:36,330 this folder in order to serve some 17 00:00:36,360 --> 00:00:39,510 static files like index.html 18 00:00:39,510 --> 00:00:41,940 and the favicons to clients using 19 00:00:41,970 --> 00:00:44,520 nginx web server. And now it's a 20 00:00:44,520 --> 00:00:47,280 good time to take this folder and 21 00:00:47,280 --> 00:00:49,710 make two copies of this folder and 22 00:00:49,710 --> 00:00:51,660 call them 'nginx1' and 23 00:00:51,720 --> 00:00:54,240 'nginx2'. And afterwards, we 24 00:00:54,240 --> 00:00:55,920 will spin up two different 25 00:00:55,920 --> 00:00:58,650 containers running nginx server, and 26 00:00:58,650 --> 00:01:00,810 we will expose them to do different 27 00:01:00,840 --> 00:01:02,910 external ports on this computer. 28 00:01:03,180 --> 00:01:05,250 Let's do so. If you don't have this 29 00:01:05,250 --> 00:01:07,200 'nginx' folder, you could take it 30 00:01:07,230 --> 00:01:09,360 from GitHub repository, just clone 31 00:01:09,360 --> 00:01:11,460 it, find 'containers' folder there, 32 00:01:11,610 --> 00:01:13,560 and then find 'nginx' folder. 33 00:01:13,800 --> 00:01:16,590 Great. Let me copy this folder, 34 00:01:16,740 --> 00:01:19,590 right mouse click, Copy, and paste 35 00:01:19,620 --> 00:01:22,770 here like so. And let me rename it, 36 00:01:22,770 --> 00:01:26,652 press Enter, and it will be 'nginx1' 37 00:01:26,652 --> 00:01:28,920 like so. And let's make one 38 00:01:28,920 --> 00:01:33,510 more copy, paste, and let's name it 39 00:01:33,540 --> 00:01:37,830 'nginx2', like so. Next, let's open 40 00:01:37,830 --> 00:01:40,290 up 'nginx1' folder, and open 41 00:01:40,320 --> 00:01:43,170 index.html file there. Let's first 42 00:01:43,170 --> 00:01:45,270 close this index.html file 43 00:01:45,270 --> 00:01:47,550 that was opened in nginx folder. 44 00:01:47,640 --> 00:01:50,929 Okay, so nginx1, and index.html. 45 00:01:50,929 --> 00:01:52,980 And here let's adjust this 46 00:01:53,010 --> 00:01:59,160 text, 'Hello from the FIRST nginx 47 00:01:59,430 --> 00:02:01,920 server, like so. Let's save this 48 00:02:01,920 --> 00:02:04,650 file. Next collapse nginx1 49 00:02:04,650 --> 00:02:07,260 folder, expand nginx2 folder, and 50 00:02:07,290 --> 00:02:10,229 open index.html file there. And 51 00:02:10,258 --> 00:02:12,690 let's adjust text here, Hello from 52 00:02:12,690 --> 00:02:18,030 the SECOND nginx server'. And also 53 00:02:18,030 --> 00:02:20,400 we could adjust the titles here, and 54 00:02:20,400 --> 00:02:22,050 instead of 'Document' here will 55 00:02:22,050 --> 00:02:26,070 be, let's say 'NGINX2', and let's 56 00:02:26,070 --> 00:02:28,380 save this file, go to nginx1 57 00:02:28,380 --> 00:02:30,570 folder, and index.html file 58 00:02:30,630 --> 00:02:32,310 inside of that folder, and adjust 59 00:02:32,310 --> 00:02:34,740 the document here, and here will be 60 00:02:34,770 --> 00:02:37,740 'NGINX1'. Let's save the file. 61 00:02:37,890 --> 00:02:39,630 And now we are all set. And now we 62 00:02:39,630 --> 00:02:41,370 are able to start two different 63 00:02:41,370 --> 00:02:43,020 containers in two different 64 00:02:43,020 --> 00:02:45,810 folders. Great. Let me close those 65 00:02:45,810 --> 00:02:48,900 two index.html files, and go to 66 00:02:48,900 --> 00:02:51,600 terminal. Recap that we have started 67 00:02:51,600 --> 00:02:53,940 the standalone nginx container 68 00:02:54,090 --> 00:02:57,420 using 'PWD' variable. And now we 69 00:02:57,420 --> 00:02:59,370 will do the same. But if you want 70 00:02:59,370 --> 00:03:01,320 to use variable instead of absolute 71 00:03:01,320 --> 00:03:03,570 path, you need to first 'cd' to 72 00:03:03,570 --> 00:03:05,580 corresponding folder that has 73 00:03:05,700 --> 00:03:08,220 needed files and only then run 74 00:03:08,280 --> 00:03:09,750 'docker run' command inside of that 75 00:03:09,750 --> 00:03:12,060 folder. Let's do so. Here will be 76 00:03:12,060 --> 00:03:14,340 'nginx1' server, and here will be 77 00:03:14,370 --> 00:03:17,730 'nginx2' server. Let's 'cd' to 'Desktop/ 78 00:03:17,910 --> 00:03:21,870 containers/nginx1', like so. And 79 00:03:21,870 --> 00:03:24,480 here let's 'cd' to 'Desktop/containers/ 80 00:03:24,600 --> 00:03:28,110 nginx2'. Great. Let's now start 81 00:03:28,110 --> 00:03:30,210 the nginx1 container, and for 82 00:03:30,210 --> 00:03:32,130 that we will use as usually 'docker 83 00:03:32,130 --> 00:03:35,100 run' command. Next let's expose port 84 00:03:35,130 --> 00:03:37,860 '-p', and let's run nginx1 85 00:03:37,860 --> 00:03:42,990 server on port, let's say 5555, and 86 00:03:43,020 --> 00:03:45,690 internal port will be 80, and 87 00:03:45,690 --> 00:03:48,159 next comes volume mapping, '-v', 88 00:03:48,159 --> 00:03:51,742 here will be variable 'PWD', 89 00:03:51,742 --> 00:03:53,940 next comes ':', and after 90 00:03:53,940 --> 00:03:56,280 ':' you need to specify path to 91 00:03:56,310 --> 00:03:58,800 files inside of the container. And 92 00:03:58,800 --> 00:04:04,110 this path is 'usr/share/nginx/html', 93 00:04:04,650 --> 00:04:08,160 like so. And finally comes name of 94 00:04:08,220 --> 00:04:12,030 nginx image, 'nginx'. Also Optionally, 95 00:04:12,030 --> 00:04:13,800 you could specify the name of the 96 00:04:13,800 --> 00:04:16,019 container. Recap that if you don't 97 00:04:16,019 --> 00:04:17,519 specify the name of the container, 98 00:04:17,730 --> 00:04:20,220 then Docker will generate random 99 00:04:20,220 --> 00:04:21,810 name and you have seen such random 100 00:04:21,810 --> 00:04:23,700 names before. But you are able to 101 00:04:23,700 --> 00:04:25,709 add custom name if you want to. And 102 00:04:25,709 --> 00:04:28,750 for that you could use option '--name', 103 00:04:28,750 --> 00:04:30,210 and here let's name this 104 00:04:30,210 --> 00:04:33,030 container 'nginx1', like so. 105 00:04:33,540 --> 00:04:36,090 Great. Let's press Enter, and see 106 00:04:36,090 --> 00:04:38,250 what will happen. Container is 107 00:04:38,250 --> 00:04:39,930 running. We are actually inside of 108 00:04:39,960 --> 00:04:41,520 it and we are ready to see some 109 00:04:41,520 --> 00:04:44,250 logs. Great. Let's now do the same 110 00:04:44,250 --> 00:04:47,400 here for nginx to web server, 'docker 111 00:04:47,400 --> 00:04:50,010 run -p'. Let's expose it to 112 00:04:50,010 --> 00:04:53,640 port 6666 like so, and internal port 113 00:04:53,640 --> 00:04:55,290 will be again 80 because that's 114 00:04:55,290 --> 00:04:57,300 the port that is opened by nginx 115 00:04:57,330 --> 00:04:59,190 server inside of the container by 116 00:04:59,190 --> 00:05:01,700 default. Next comes the volume mapping, 117 00:05:02,760 --> 00:05:06,000 same variable 'PWD', it is important, 118 00:05:06,030 --> 00:05:08,190 same variable, and it will be 119 00:05:08,190 --> 00:05:10,830 replaced by absolute path for each 120 00:05:10,860 --> 00:05:12,750 of those folders - nginx2, and 121 00:05:12,780 --> 00:05:15,570 nginx1 in our case. And here, 122 00:05:15,600 --> 00:05:17,670 let's after colon specifies same 123 00:05:17,700 --> 00:05:20,880 internal folder, '/usr/share/nginx/ 124 00:05:21,300 --> 00:05:23,880 html'. And let's give name to this 125 00:05:23,880 --> 00:05:27,960 container 'nginx2 nginx'. Okay, 126 00:05:28,110 --> 00:05:29,940 let's press Enter, and start this 127 00:05:29,970 --> 00:05:32,970 second nginx server. Now we are all 128 00:05:32,970 --> 00:05:34,950 set. And those two containers are 129 00:05:34,950 --> 00:05:36,810 now running. And in order to verify 130 00:05:36,810 --> 00:05:38,430 it, you can simply open up Google 131 00:05:38,430 --> 00:05:40,650 Chrome and try to connect to those 132 00:05:40,650 --> 00:05:44,580 two ports, 5555 and 6666. Let's do 133 00:05:44,580 --> 00:05:47,250 so. Let's go to Google Chrome, and 134 00:05:47,250 --> 00:05:49,470 here we could use a localhost. But 135 00:05:49,470 --> 00:05:51,120 recap that you're also able to use 136 00:05:51,180 --> 00:05:54,870 a loopback IP address 127.0.0.1 or 137 00:05:54,900 --> 00:05:56,640 any of the IP addresses of your 138 00:05:56,640 --> 00:05:58,920 computer. I'll use a localhost, so 139 00:05:58,920 --> 00:06:00,900 'localhost', and here let's 140 00:06:00,900 --> 00:06:03,210 connect to first nginx server. 141 00:06:04,500 --> 00:06:06,600 'Hello from the FIRST Nginx server!'. 142 00:06:07,140 --> 00:06:10,170 Let's open up a new tab. 'localhost 143 00:06:12,000 --> 00:06:17,310 :6666'. 'This site can't be reached', 144 00:06:17,550 --> 00:06:19,980 something is wrong. Let's go to 145 00:06:20,040 --> 00:06:22,080 terminal and verify what's actually 146 00:06:22,080 --> 00:06:25,200 happening here. '/usr/share/nginx'. 147 00:06:25,200 --> 00:06:27,200 [no audio] 148 00:06:27,200 --> 00:06:29,400 No logs here. And the command seems 149 00:06:29,490 --> 00:06:31,530 working properly. Let's go back 150 00:06:31,530 --> 00:06:33,660 to Chrome. Yeah, and actually, I 151 00:06:33,660 --> 00:06:36,300 see here error, 'ERR_UNSAFE_PORT'. 152 00:06:36,720 --> 00:06:38,520 It seems that I'm not able to 153 00:06:38,520 --> 00:06:42,390 expose the such port, 6666. Okay, 154 00:06:42,390 --> 00:06:44,910 let's rerun this container, and use 155 00:06:44,940 --> 00:06:47,490 another port. Let's close this, and 156 00:06:47,550 --> 00:06:51,540 let's run it at port, let's say 157 00:06:52,080 --> 00:06:55,680 7777. And I see error from Docker, 158 00:06:55,710 --> 00:06:56,940 'Error response from daemon: 159 00:06:56,940 --> 00:06:59,447 Conflict. The container name "/nginx2" 160 00:06:59,447 --> 00:07:01,170 is already in use by another 161 00:07:01,170 --> 00:07:03,060 container'. But actually, I have 162 00:07:03,060 --> 00:07:04,950 just stopped this container with 163 00:07:04,950 --> 00:07:07,290 custom name. But it still exists 164 00:07:07,320 --> 00:07:09,000 and you are able to start it over 165 00:07:09,000 --> 00:07:10,860 again. You could verify that by 166 00:07:10,920 --> 00:07:12,480 entering 'docker ps', and you should 167 00:07:12,480 --> 00:07:14,160 see only one container running, and 168 00:07:14,160 --> 00:07:15,720 yes, that is a case here we see 169 00:07:15,720 --> 00:07:17,160 this container that is running here 170 00:07:17,160 --> 00:07:19,260 in this window. But if you type 171 00:07:19,260 --> 00:07:21,720 'docker ps -a', you will see that 172 00:07:21,750 --> 00:07:23,850 this container, it should be 173 00:07:23,850 --> 00:07:26,130 somewhere at the top, was exited, 174 00:07:26,160 --> 00:07:28,110 but it is still available for use, 175 00:07:28,110 --> 00:07:30,300 and you are able to restart if you 176 00:07:30,300 --> 00:07:31,980 want to. Here was actually this 177 00:07:31,980 --> 00:07:33,990 container with name 'nginx2'. 178 00:07:34,260 --> 00:07:35,940 That's why we need to remove this 179 00:07:35,940 --> 00:07:37,380 container first before starting 180 00:07:37,380 --> 00:07:39,600 container with the same name. And I 181 00:07:39,600 --> 00:07:41,280 could remove container by typing 182 00:07:41,340 --> 00:07:44,520 'docker rm', and here will be either 183 00:07:44,520 --> 00:07:47,430 ID of the container or its name, we 184 00:07:47,460 --> 00:07:50,160 could use here name, 'nginx2', like 185 00:07:50,160 --> 00:07:53,010 so. Container was removed. And now I 186 00:07:53,010 --> 00:07:54,750 am able to try to start 187 00:07:54,750 --> 00:07:56,460 container with the same name again. 188 00:07:56,760 --> 00:07:58,860 Let's clear terminal here, and 189 00:07:58,890 --> 00:08:02,250 again go back to history and find 190 00:08:02,280 --> 00:08:04,380 this command. And let's try to start 191 00:08:04,380 --> 00:08:08,040 this container and expose port 7777, 192 00:08:08,520 --> 00:08:12,270 Enter, let's go to Chrome, and 193 00:08:12,270 --> 00:08:13,680 here instead of this port, let's 194 00:08:13,680 --> 00:08:17,490 use this port, Enter, and I see 195 00:08:17,490 --> 00:08:19,080 response, 'Hello from the SECOND 196 00:08:19,110 --> 00:08:21,300 Nginx server!'. Basically I have no 197 00:08:21,300 --> 00:08:24,570 idea why port 6666 is considered 198 00:08:24,570 --> 00:08:26,850 unsafe. Actually, let me Google it 199 00:08:26,850 --> 00:08:32,909 quickly, '6666 unsafe port', and 200 00:08:32,909 --> 00:08:34,260 let's check out this first link, 201 00:08:34,260 --> 00:08:36,030 'Which ports are considered unsafe 202 00:08:36,030 --> 00:08:39,120 by Chrome?' We'll scroll down a bit, 203 00:08:39,330 --> 00:08:41,669 and here is a list of all ports 204 00:08:41,730 --> 00:08:43,770 that are considered as restricted. 205 00:08:43,950 --> 00:08:45,750 Actually, you see here a list of 206 00:08:45,929 --> 00:08:47,280 default ports for different 207 00:08:47,280 --> 00:08:50,220 applications like Port 22 for 'ssh', 208 00:08:50,309 --> 00:08:52,590 and so on. And let me scroll down 209 00:08:52,620 --> 00:08:55,169 and yes here is the list of ports in 210 00:08:55,169 --> 00:08:57,900 this range. And this port 6666 211 00:08:57,990 --> 00:09:01,230 is an 'Alternator IRC [Apple addition]' port. 212 00:09:01,410 --> 00:09:03,450 Actually I don't know what is IRC, 213 00:09:04,500 --> 00:09:06,420 let me check what is that quickly. 214 00:09:08,310 --> 00:09:10,890 IRC is Internet Relay Chat, is a 215 00:09:10,890 --> 00:09:12,570 system that facilitates transfer 216 00:09:12,570 --> 00:09:15,120 messages in the form of text'. Okay, 217 00:09:15,210 --> 00:09:16,740 it's some sort of chatting 218 00:09:16,770 --> 00:09:18,870 application. Great. That's how we 219 00:09:18,900 --> 00:09:21,210 found out that we are not able to 220 00:09:21,210 --> 00:09:24,090 expose such port and use it for 221 00:09:24,090 --> 00:09:26,220 our nginx server, or any other 222 00:09:26,220 --> 00:09:28,500 container basically. Great. We have 223 00:09:28,500 --> 00:09:30,480 achieved actually our goal, and we 224 00:09:30,480 --> 00:09:32,160 are able to summarize what we have 225 00:09:32,160 --> 00:09:33,840 achieved in this lecture. And we 226 00:09:33,840 --> 00:09:35,940 have created two different nginx 227 00:09:35,940 --> 00:09:38,670 servers here with first server and 228 00:09:38,670 --> 00:09:40,350 we have served content from the 229 00:09:40,380 --> 00:09:43,140 'nginx1' folder, and here was 230 00:09:43,140 --> 00:09:45,390 the second nginx server and it 231 00:09:45,420 --> 00:09:47,640 serves content from the nginx2 232 00:09:47,640 --> 00:09:49,620 folder, and here we have actually 233 00:09:49,620 --> 00:09:51,330 verified that. Here you see, 'Hello 234 00:09:51,330 --> 00:09:53,010 from the SECOND Nginx server!'; and 235 00:09:53,010 --> 00:09:55,334 here is the document title, NGINX2; 236 00:09:55,334 --> 00:09:56,700 and here in this tab you see 237 00:09:56,700 --> 00:09:58,830 document title, 'NGINX1', and 238 00:09:58,830 --> 00:10:00,570 'Hello from the FIRST Nginx 239 00:10:00,570 --> 00:10:03,120 server!'. And of course, anytime when 240 00:10:03,120 --> 00:10:05,490 you edit the files in those two 241 00:10:05,490 --> 00:10:07,380 folders, and refresh the page 242 00:10:07,410 --> 00:10:08,940 afterwards in Google Chrome, you'll 243 00:10:08,940 --> 00:10:11,460 see updated page. For example, if I 244 00:10:11,490 --> 00:10:14,280 change index.html file here in 245 00:10:14,280 --> 00:10:16,650 nginx2 folder, and add one more 246 00:10:16,680 --> 00:10:19,230 exclamation mark here, go to Google 247 00:10:19,230 --> 00:10:21,240 Chrome back, go to nginx2, 248 00:10:21,270 --> 00:10:22,650 refresh page, you will see 249 00:10:22,680 --> 00:10:25,260 updated text here. That's how 250 00:10:25,260 --> 00:10:27,240 you're able to start multiple 251 00:10:27,240 --> 00:10:28,860 nginx servers. But it is 252 00:10:28,860 --> 00:10:30,990 important that you need to use 253 00:10:31,020 --> 00:10:33,270 different external ports, because 254 00:10:33,270 --> 00:10:35,730 on your computer, each port may be 255 00:10:35,730 --> 00:10:38,190 utilized only by one application. 256 00:10:38,400 --> 00:10:40,590 And in this case, those two ports, 257 00:10:40,620 --> 00:10:42,840 this port and this port will be 258 00:10:42,840 --> 00:10:44,970 actually forwarded to Docker host 259 00:10:45,000 --> 00:10:47,250 and it will actually proxy those 260 00:10:47,250 --> 00:10:49,470 ports to corresponding containers. 261 00:10:49,500 --> 00:10:50,940 That's how it works under the hood. 262 00:10:51,300 --> 00:10:53,130 Great. That's all for this lecture. 263 00:10:53,130 --> 00:10:54,480 I hope that you have enjoyed it, and 264 00:10:54,480 --> 00:10:56,250 we've found some interesting stuff. 265 00:10:56,490 --> 00:10:57,990 And in the next lecture, let's 266 00:10:58,020 --> 00:11:00,030 start with Python; and let's create 267 00:11:00,030 --> 00:11:02,160 a simple Python application and run 268 00:11:02,160 --> 00:11:03,900 it inside of the container. I will 269 00:11:03,900 --> 00:11:05,652 see you in the next lecture. Bye-Bye. 270 00:11:05,652 --> 00:11:07,178 [no audio]