1 00:00:00,000 --> 00:00:04,500 [Intro Music] 2 00:00:04,500 --> 00:00:06,240 I just made a quick overview of the 3 00:00:06,240 --> 00:00:08,310 mongo and mongo-express official 4 00:00:08,310 --> 00:00:10,290 Docker images; and now it's time to 5 00:00:10,290 --> 00:00:12,060 create two additional services in 6 00:00:12,090 --> 00:00:15,000 our own 'docker-compose' file; and add 7 00:00:15,000 --> 00:00:17,580 there mongo and mongo-express 8 00:00:17,580 --> 00:00:19,920 services. In order to save some 9 00:00:19,920 --> 00:00:22,950 time, let's simply grab those lines 10 00:00:22,950 --> 00:00:24,930 from this example and insert them 11 00:00:24,930 --> 00:00:26,700 to the 'docker-compose' file. Let's 12 00:00:26,700 --> 00:00:28,770 go there, and let's insert those 13 00:00:28,770 --> 00:00:32,340 services below 'api' here. Make sure 14 00:00:32,340 --> 00:00:34,350 that you go to the same level as 15 00:00:34,380 --> 00:00:36,780 'api' and 'frontend' services here in 16 00:00:36,780 --> 00:00:39,450 this YAML file, and paste copied 17 00:00:39,450 --> 00:00:41,760 lines like that, and make sure that 18 00:00:41,820 --> 00:00:44,400 formatting is correct. And let's of 19 00:00:44,400 --> 00:00:46,290 course make some adjustments here. 20 00:00:46,740 --> 00:00:49,050 First service is mongo; and here 21 00:00:49,080 --> 00:00:52,110 we specify image. And it means for 22 00:00:52,110 --> 00:00:54,030 Docker, that we want to use 23 00:00:54,060 --> 00:00:56,220 official image from the Docker Hub. 24 00:00:56,610 --> 00:00:59,160 Here is name of such image. And 25 00:00:59,160 --> 00:01:00,630 if you want you could also add here 26 00:01:00,630 --> 00:01:03,630 tag 'latest', but we will omit it, in 27 00:01:03,630 --> 00:01:05,550 such case Docker will add tag 28 00:01:05,550 --> 00:01:07,620 'latest' automatically. Let's keep 29 00:01:07,620 --> 00:01:10,140 'restart: always' here and here same 30 00:01:10,170 --> 00:01:12,420 as in the example. In such case, Docker 31 00:01:12,420 --> 00:01:13,770 will restart containers 32 00:01:13,770 --> 00:01:15,150 automatically, in case of any 33 00:01:15,150 --> 00:01:17,820 failures. 'environment' variables here 34 00:01:17,820 --> 00:01:20,550 will be kept as you see here. But 35 00:01:20,550 --> 00:01:22,470 let's change this 'example' password 36 00:01:22,650 --> 00:01:25,830 to another, let's say, 'very- 37 00:01:26,100 --> 00:01:29,490 strong-db-password', like 38 00:01:29,490 --> 00:01:32,010 that. And also, let's take this 39 00:01:32,010 --> 00:01:34,740 password and insert it here instead 40 00:01:34,740 --> 00:01:37,440 of this 'example' password. Also, here 41 00:01:37,530 --> 00:01:39,930 in mongo-express section, let's add 42 00:01:39,960 --> 00:01:41,730 one more environment variable 43 00:01:41,880 --> 00:01:45,477 called 'ME_CONFIG_ 44 00:01:45,477 --> 00:01:48,570 MONGODB_ 45 00:01:48,600 --> 00:01:51,600 SEVER:', and value will be 46 00:01:51,600 --> 00:01:54,660 'mongo'. It is name of that 'mongo' 47 00:01:54,660 --> 00:01:57,120 service here. And I told you in the 48 00:01:57,120 --> 00:01:59,190 previous lecture that such mongo 49 00:01:59,190 --> 00:02:01,410 hostname inside of the Docker will 50 00:02:01,410 --> 00:02:03,960 be resolved by DNS of the Docker, 51 00:02:04,200 --> 00:02:06,150 to corresponding IP address of the 52 00:02:06,150 --> 00:02:08,460 running container, container that 53 00:02:08,460 --> 00:02:10,830 will be running mongo service. And of 54 00:02:10,830 --> 00:02:12,240 course, I'll show you how it looks 55 00:02:12,240 --> 00:02:15,360 from inside. Also, here, you see 56 00:02:15,390 --> 00:02:19,110 port mapping; and internal port 8081 57 00:02:19,140 --> 00:02:21,660 inside of the mongo-express is 58 00:02:21,660 --> 00:02:23,370 mapped to external port on your 59 00:02:23,370 --> 00:02:26,370 computer 8081. And that means 60 00:02:26,370 --> 00:02:28,080 that you will be able to access 61 00:02:28,110 --> 00:02:30,060 graphical user interface of the 62 00:02:30,060 --> 00:02:32,220 mongo-express because it has 63 00:02:32,220 --> 00:02:34,170 actually GUI. It is based on the 64 00:02:34,320 --> 00:02:37,590 express and Node.js, and it means that 65 00:02:37,590 --> 00:02:38,940 you will be able to access it in 66 00:02:38,940 --> 00:02:41,310 any web browser using localhost 67 00:02:41,370 --> 00:02:44,820 :8081 address. But 68 00:02:44,820 --> 00:02:47,340 notice that mongo doesn't have any 69 00:02:47,370 --> 00:02:49,830 exposed ports. It does not mean 70 00:02:49,830 --> 00:02:51,840 that the mongo does not utilize 71 00:02:51,870 --> 00:02:53,220 ports. Of course, it uses 72 00:02:53,220 --> 00:02:54,630 corresponding ports in order to be 73 00:02:54,630 --> 00:02:56,760 able to accept incoming requests. 74 00:02:57,570 --> 00:03:01,620 But mongo will not be exposed to 75 00:03:01,620 --> 00:03:04,110 outside world. It will be available 76 00:03:04,140 --> 00:03:07,320 only from other containers, for 77 00:03:07,320 --> 00:03:09,870 example, from mongo-express, or from 78 00:03:09,900 --> 00:03:12,720 'api', because usually 'api' servers 79 00:03:12,720 --> 00:03:14,190 communicate directly with 80 00:03:14,190 --> 00:03:17,130 databases. And in our project 'api' 81 00:03:17,130 --> 00:03:19,110 container should interact with 82 00:03:19,140 --> 00:03:21,810 mongo container, and it is possible 83 00:03:21,810 --> 00:03:24,480 inside of the Docker, using mongo 84 00:03:24,510 --> 00:03:26,190 as a hostname of the mongo 85 00:03:26,190 --> 00:03:29,010 container. And again, there is no 86 00:03:29,010 --> 00:03:31,710 need to expose mongo to outside 87 00:03:31,710 --> 00:03:33,870 world, and to add port mapping. 88 00:03:34,470 --> 00:03:36,690 mongo-express will communicate with 89 00:03:36,690 --> 00:03:40,530 mongo internally. Alright, that's 90 00:03:40,530 --> 00:03:42,000 actually all configuration that 91 00:03:42,000 --> 00:03:43,950 needs to be done in order to bring 92 00:03:44,040 --> 00:03:46,440 up two additional services, mongo 93 00:03:46,500 --> 00:03:49,470 and mongo-express. And basically, let 94 00:03:49,470 --> 00:03:51,450 me add one more instruction here, 95 00:03:51,750 --> 00:03:54,600 and it is called 'depends_ 96 00:03:54,600 --> 00:03:56,850 on', and with such instruction in 97 00:03:56,850 --> 00:03:59,310 place, you could add list of the 98 00:03:59,310 --> 00:04:02,580 containers that current container 99 00:04:02,640 --> 00:04:04,860 depends on. And with such 100 00:04:04,860 --> 00:04:06,510 configuration, if you enter here, 101 00:04:06,510 --> 00:04:08,910 for instance, mongo, mongo-express 102 00:04:08,910 --> 00:04:10,710 container will be started by 103 00:04:10,710 --> 00:04:13,500 Docker, only after the start of the 104 00:04:13,500 --> 00:04:16,320 mongo container. That's what 'depends_ 105 00:04:16,350 --> 00:04:18,779 on' instruction means. That's why 106 00:04:18,810 --> 00:04:20,399 let's give this instruction here. 107 00:04:20,579 --> 00:04:22,260 We want to start mongo-express 108 00:04:22,320 --> 00:04:24,720 after mongo; and let's save changes 109 00:04:24,720 --> 00:04:26,880 here in this 'docker-compose' file. 110 00:04:27,360 --> 00:04:28,950 Now, there are four different 111 00:04:28,950 --> 00:04:31,980 services frontend, api, mongo and 112 00:04:31,980 --> 00:04:34,800 mongo-express. Let's now go ahead 113 00:04:34,800 --> 00:04:36,840 and using 'docker-compose up' 114 00:04:36,840 --> 00:04:38,940 command, bring up those two 115 00:04:38,970 --> 00:04:40,830 additional services. But let's do 116 00:04:40,830 --> 00:04:42,724 that of course after the small pause. 117 00:04:42,724 --> 00:04:45,120 [no audio]