1 00:00:00,000 --> 00:00:04,200 [Intro Music] 2 00:00:04,230 --> 00:00:06,000 We have just successfully created 3 00:00:06,000 --> 00:00:08,130 the new custom bridge network. It is 4 00:00:08,130 --> 00:00:10,080 called 'custom', and this driver is 5 00:00:10,080 --> 00:00:12,570 bridge. And here you'll see Subnet 6 00:00:12,600 --> 00:00:14,700 that will be used for assignment of 7 00:00:14,700 --> 00:00:16,830 the IP addresses to containers in 8 00:00:16,860 --> 00:00:20,160 this custom network. Now let's stop 9 00:00:20,160 --> 00:00:21,660 those two containers that we 10 00:00:21,660 --> 00:00:23,460 have created in default bridge 11 00:00:23,460 --> 00:00:25,140 network; and afterwards, let's 12 00:00:25,140 --> 00:00:27,990 create again two new containers in 13 00:00:27,990 --> 00:00:30,660 custom network, but we will not use 14 00:00:30,690 --> 00:00:32,939 now '--name' option; and we 15 00:00:32,939 --> 00:00:35,100 will not use '-h', hostname 16 00:00:35,130 --> 00:00:37,410 option. We will let Docker create 17 00:00:37,410 --> 00:00:40,200 custom names on its own. Great. Let 18 00:00:40,200 --> 00:00:42,870 me exit from this sh shell, clear 19 00:00:42,870 --> 00:00:45,060 terminal here, and let me exit from 20 00:00:45,210 --> 00:00:47,400 this sh shell, clear terminal as 21 00:00:47,400 --> 00:00:49,530 well, and let me actually using 22 00:00:49,560 --> 00:00:52,260 'docker container prune' remove 23 00:00:52,290 --> 00:00:54,930 existing containers. Yes. And 24 00:00:54,960 --> 00:00:56,430 afterwards, let's clear terminal, 25 00:00:56,460 --> 00:00:58,470 and start first container 26 00:00:58,470 --> 00:01:01,710 here using 'docker run -it 27 00:01:01,770 --> 00:01:04,500 busybox' command, like so without 28 00:01:04,530 --> 00:01:07,200 name option and without h option. 29 00:01:07,500 --> 00:01:09,840 But we will add additional option. 30 00:01:10,020 --> 00:01:12,480 Basically let me first run here 31 00:01:12,480 --> 00:01:14,100 'docker run --help' 32 00:01:14,100 --> 00:01:16,500 command and show you option that we 33 00:01:16,500 --> 00:01:19,200 will use now, it is '--network' 34 00:01:19,200 --> 00:01:21,300 option, here it is. And 35 00:01:21,360 --> 00:01:23,160 with this option, we are able to 36 00:01:23,160 --> 00:01:25,380 connect container to specific 37 00:01:25,410 --> 00:01:27,750 network. And again by default 38 00:01:27,780 --> 00:01:29,970 without this option, containers are 39 00:01:29,970 --> 00:01:32,610 attached to default bridge network. 40 00:01:33,030 --> 00:01:34,890 Great. Let's use this option. 41 00:01:35,730 --> 00:01:39,404 'docker run -it --network', 42 00:01:39,404 --> 00:01:41,610 and after this parameter, 43 00:01:41,640 --> 00:01:43,200 let's specify the name of the 44 00:01:43,200 --> 00:01:45,450 custom network we want to connect 45 00:01:45,480 --> 00:01:47,730 this container to. And in our case 46 00:01:47,760 --> 00:01:49,890 name is simply 'custom'. Let's type 47 00:01:49,890 --> 00:01:51,960 this name like so. And afterwards, 48 00:01:51,990 --> 00:01:54,060 let's type the name of the image we 49 00:01:54,090 --> 00:01:56,010 want to use for this container. And 50 00:01:56,010 --> 00:01:57,510 name will be same as before, 51 00:01:57,570 --> 00:02:00,510 'busybox'. 'busybox'. Let's press 52 00:02:00,510 --> 00:02:03,630 Enter. And let's verify which IP 53 00:02:03,630 --> 00:02:05,460 address was assigned to this 54 00:02:05,490 --> 00:02:09,227 'busybox' container. 'hostname -i'; 55 00:02:09,227 --> 00:02:11,280 and here you see address 56 00:02:11,430 --> 00:02:13,470 from network range that was 57 00:02:13,500 --> 00:02:15,960 assigned to our custom bridge 58 00:02:15,960 --> 00:02:18,510 network, this range. And if I'll 59 00:02:18,510 --> 00:02:20,520 enter here, 'docker network inspect 60 00:02:20,520 --> 00:02:22,320 custom', you should see now 61 00:02:22,320 --> 00:02:24,750 container that was attached to this 62 00:02:24,780 --> 00:02:26,490 custom network. Here are the 63 00:02:26,490 --> 00:02:27,840 details about this first 64 00:02:27,840 --> 00:02:29,760 container. Here is its random 65 00:02:29,760 --> 00:02:32,730 name, "heuristic_lumiere'; here is 66 00:02:32,760 --> 00:02:34,620 MacAddress; and here's IP address, 67 00:02:34,650 --> 00:02:37,260 same as we see here in this output. 68 00:02:37,650 --> 00:02:40,230 Great. Let's now in the same way, 69 00:02:40,260 --> 00:02:42,480 create one more 'busybox' container. 70 00:02:42,660 --> 00:02:45,300 Let's go to this step, 'docker run 71 00:02:45,330 --> 00:02:47,820 -it --network', 72 00:02:47,820 --> 00:02:50,800 again 'custom' here, and the name of 73 00:02:50,850 --> 00:02:53,501 the container, image sorry, 'busybox', 74 00:02:53,501 --> 00:02:56,730 Enter. And let's verify IP 75 00:02:56,730 --> 00:02:58,410 address of this container, 'hostname 76 00:02:58,410 --> 00:03:03,000 -i', 172.18.0.3. Let's go back to 77 00:03:03,000 --> 00:03:05,220 this last step, and verify whether 78 00:03:05,220 --> 00:03:07,440 this container was attached to this 79 00:03:07,440 --> 00:03:09,450 'custom' network. And yes, now I see 80 00:03:09,450 --> 00:03:11,700 here in this output two containers 81 00:03:12,180 --> 00:03:13,530 with different IP addresses of 82 00:03:13,530 --> 00:03:15,630 course. Here is first container. 83 00:03:15,840 --> 00:03:18,270 Here it is. And here's the second 84 00:03:18,270 --> 00:03:20,880 container. Here you see IDs of 85 00:03:20,880 --> 00:03:22,920 containers, here ID of the first 86 00:03:22,920 --> 00:03:24,750 container, and here is ID of the 87 00:03:24,750 --> 00:03:26,550 second container. And here are 88 00:03:26,610 --> 00:03:28,800 their IP addresses, this one and 89 00:03:28,800 --> 00:03:31,320 this one. Wonderful. Let's now 90 00:03:31,320 --> 00:03:33,840 verify connectivity between those 91 00:03:33,870 --> 00:03:36,360 two 'busybox' containers; and first 92 00:03:36,360 --> 00:03:38,580 let's as usually ping using IP 93 00:03:38,580 --> 00:03:43,110 address 172.18.0.3. And yes, I get the 94 00:03:43,110 --> 00:03:45,570 response from second container. And 95 00:03:45,570 --> 00:03:48,720 now let's try to ping by hostname. 96 00:03:49,110 --> 00:03:51,210 Let's check hostname of this 97 00:03:51,270 --> 00:03:54,300 container, 'hostname' like so. Here 98 00:03:54,300 --> 00:03:56,970 is hostname. Let's copy it, go 99 00:03:56,970 --> 00:04:00,000 here, and use this hostname with 100 00:04:00,000 --> 00:04:02,580 ping command. And now I get 101 00:04:02,580 --> 00:04:05,160 response. It means that using 102 00:04:05,190 --> 00:04:07,950 custom network we are able to 103 00:04:07,950 --> 00:04:09,570 communicate between containers 104 00:04:09,720 --> 00:04:12,570 using their hostnames. It is a 105 00:04:12,570 --> 00:04:15,120 very important outcome. And that's 106 00:04:15,120 --> 00:04:17,339 how picture differs from default 107 00:04:17,370 --> 00:04:19,529 bridge network, where we were not 108 00:04:19,560 --> 00:04:21,959 able to communicate using hostnames. 109 00:04:22,680 --> 00:04:25,290 Great. Let's now verify whether we 110 00:04:25,290 --> 00:04:27,120 will be able to communicate between 111 00:04:27,120 --> 00:04:31,170 containers using their names. Recap 112 00:04:31,170 --> 00:04:33,750 the names were assigned randomly by 113 00:04:33,750 --> 00:04:36,150 Docker. Let's clear terminal, and 114 00:04:36,180 --> 00:04:38,100 actually you're able to find out 115 00:04:38,130 --> 00:04:39,600 which names were assigned to 116 00:04:39,600 --> 00:04:41,250 containers here in this section. 117 00:04:41,520 --> 00:04:43,620 Name is here for container with 118 00:04:43,650 --> 00:04:45,990 this IP address. And basically its 119 00:04:45,990 --> 00:04:47,700 container running in my case in 120 00:04:47,700 --> 00:04:50,400 this first step; and name for second 121 00:04:50,400 --> 00:04:53,100 container is here. Here it is. And 122 00:04:53,100 --> 00:04:55,290 now using this name let me try to 123 00:04:55,290 --> 00:04:57,690 access second container using same 124 00:04:57,720 --> 00:04:59,970 ping command from first container, 125 00:05:00,000 --> 00:05:02,640 this one. 'ping', and let me paste 126 00:05:02,640 --> 00:05:04,770 the name of the second container; 127 00:05:04,830 --> 00:05:08,340 not hostname, name; Enter; and I see 128 00:05:08,400 --> 00:05:11,550 'bad address'. Great. That's outcome 129 00:05:11,580 --> 00:05:14,040 we have at the moment. We are able 130 00:05:14,040 --> 00:05:15,930 to communicate between containers 131 00:05:16,140 --> 00:05:18,990 using their hostnames. But 132 00:05:18,990 --> 00:05:21,570 hostnames are actually random. And 133 00:05:21,600 --> 00:05:24,240 they are assigned randomly. And 134 00:05:24,270 --> 00:05:26,610 they are actually based on ID of 135 00:05:26,610 --> 00:05:28,500 specific container. Here, you see 136 00:05:28,500 --> 00:05:30,990 that, 'hostname', you see first 137 00:05:30,990 --> 00:05:33,450 few characters of ID of specific 138 00:05:33,450 --> 00:05:35,610 container. Here is actually full 139 00:05:35,610 --> 00:05:38,370 ID, here it is. And of course, 140 00:05:38,370 --> 00:05:40,920 it's not convenient to use IDs for 141 00:05:40,920 --> 00:05:42,810 communication between containers. 142 00:05:43,410 --> 00:05:46,200 We also have just verified that we 143 00:05:46,200 --> 00:05:48,570 are not able to communicate between 144 00:05:48,570 --> 00:05:51,120 containers using randomly assigned 145 00:05:51,150 --> 00:05:54,210 names, this name or this name. Here 146 00:05:54,210 --> 00:05:57,660 you see response, 'bad address'. But 147 00:05:57,660 --> 00:06:00,720 now let's try to launch same two 148 00:06:00,750 --> 00:06:03,510 'busybox' containers using custom 149 00:06:03,510 --> 00:06:05,700 names instead of randomly generated, 150 00:06:06,120 --> 00:06:07,650 but let's try that of course after 151 00:06:07,650 --> 00:06:10,150 the small pause, I'll see you in a bit. Bye-Bye. 152 00:06:10,150 --> 00:06:12,373 [no audio]