1 00:00:00,000 --> 00:00:03,000 [Intro Music] 2 00:00:04,019 --> 00:00:06,089 All right, we have just made a note 3 00:00:06,149 --> 00:00:07,979 of two commands that we have used for 4 00:00:07,979 --> 00:00:10,499 launch of mysql and phpmyadmin 5 00:00:10,499 --> 00:00:12,299 containers, and we will get back to 6 00:00:12,299 --> 00:00:14,489 them a bit later. For now let's 7 00:00:14,519 --> 00:00:16,199 again create two busybox 8 00:00:16,199 --> 00:00:18,179 containers, and let's try to 9 00:00:18,389 --> 00:00:19,949 perform communication between them 10 00:00:19,979 --> 00:00:22,169 using hostnames or names of those 11 00:00:22,169 --> 00:00:24,659 containers. Let's do that. Let's 12 00:00:24,659 --> 00:00:26,819 launch first busybox container here, 13 00:00:26,849 --> 00:00:31,529 'docker run -it busybox'. Let me 14 00:00:31,529 --> 00:00:33,359 open up a new tab, and here will be 15 00:00:33,389 --> 00:00:35,489 another busybox container, 'docker 16 00:00:35,489 --> 00:00:40,319 run -it busybox', and let me 17 00:00:40,319 --> 00:00:41,849 verify which IP addresses were 18 00:00:41,849 --> 00:00:43,229 assigned to those containers, 19 00:00:43,349 --> 00:00:47,189 'hostname -i', actually those IP 20 00:00:47,189 --> 00:00:49,169 addresses are the same as were 21 00:00:49,169 --> 00:00:50,819 assigned before. But again, the 22 00:00:50,819 --> 00:00:52,049 reason for that is that there are 23 00:00:52,079 --> 00:00:53,969 no other containers currently 24 00:00:53,969 --> 00:00:56,849 running in our setup. If there were 25 00:00:56,879 --> 00:00:58,919 additional containers with IP 26 00:00:58,919 --> 00:01:01,169 addresses that are used here now, 27 00:01:01,319 --> 00:01:03,629 for example, this one, then another 28 00:01:03,629 --> 00:01:05,129 IP address will be assigned to 29 00:01:05,129 --> 00:01:07,000 those busybox containers like 30 00:01:07,000 --> 00:01:10,300 17.0.5, 17.0.6, and so on. Great. Let's 31 00:01:10,379 --> 00:01:11,999 check the IP address of this 32 00:01:11,999 --> 00:01:14,639 container, 'hostname -i'; and it 33 00:01:14,639 --> 00:01:18,869 has address 172.17.0.2. And if you 34 00:01:18,869 --> 00:01:21,509 type 'hostname' like so, you could 35 00:01:21,509 --> 00:01:23,909 get hostname of this container, of 36 00:01:23,909 --> 00:01:28,049 this server. Also, same here, 'hostname', 37 00:01:29,189 --> 00:01:31,889 and let's now try to ping this 38 00:01:31,919 --> 00:01:35,309 busybox server by using its 'hostname', 39 00:01:35,399 --> 00:01:37,199 this one. Let me copy this 40 00:01:37,199 --> 00:01:39,359 hostname from here, go to this 41 00:01:39,359 --> 00:01:41,909 busybox container, and use same ping 42 00:01:41,909 --> 00:01:44,489 command but paste now hostname 43 00:01:44,519 --> 00:01:46,739 instead of IP address. Let's press 44 00:01:46,739 --> 00:01:50,339 Enter, and I see answer, 'bad address'; 45 00:01:51,089 --> 00:01:53,399 and that means that we are not able 46 00:01:53,429 --> 00:01:55,949 to connect to this busybox 47 00:01:55,949 --> 00:01:59,459 container using its hostname. Let 48 00:01:59,459 --> 00:02:01,109 me also show you something. Let's 49 00:02:01,109 --> 00:02:03,449 open up a new tab; and 'docker ps' 50 00:02:03,449 --> 00:02:06,449 here; and let's use 'docker inspect' 51 00:02:06,449 --> 00:02:09,989 command; and type here ID of, for 52 00:02:09,989 --> 00:02:12,508 example, this container '39' 53 00:02:12,779 --> 00:02:15,689 like so. And you'll see again 54 00:02:15,719 --> 00:02:17,549 IP address of this container, here 55 00:02:17,549 --> 00:02:20,219 it is. Gateway, default gateway that 56 00:02:20,219 --> 00:02:22,889 is same for both containers. And 57 00:02:22,889 --> 00:02:24,989 here above you will see also field 58 00:02:24,989 --> 00:02:27,569 called Aliases; and now it is set to 59 00:02:27,569 --> 00:02:30,089 null. Now let me show you how we are 60 00:02:30,119 --> 00:02:33,179 able to set custom alias for this 61 00:02:33,209 --> 00:02:35,219 container. Actually let's go back 62 00:02:35,219 --> 00:02:37,619 here, and let's exit from this 63 00:02:37,619 --> 00:02:39,509 container, and exit from this 64 00:02:39,509 --> 00:02:42,059 container as well. And now let me 65 00:02:42,059 --> 00:02:45,839 type 'docker run --help', and 66 00:02:45,839 --> 00:02:47,939 here in this output you should see 67 00:02:48,029 --> 00:02:51,509 one option called '-h', here it is 68 00:02:51,539 --> 00:02:54,149 somewhere above, '-h', and here 69 00:02:54,149 --> 00:02:55,139 you see description, it is 70 00:02:55,139 --> 00:02:57,419 'Container host name'. It means that 71 00:02:57,419 --> 00:02:59,369 using this option you are able to 72 00:02:59,369 --> 00:03:01,769 override the default hostname that 73 00:03:01,769 --> 00:03:03,119 will be assigned to specific 74 00:03:03,119 --> 00:03:06,209 container. Also you are able as you 75 00:03:06,209 --> 00:03:09,103 already know using option '--name', 76 00:03:09,103 --> 00:03:11,819 it is somewhere here, and 'n', 77 00:03:11,849 --> 00:03:13,619 yes, here it is, '--name', 78 00:03:13,859 --> 00:03:16,379 you are able to assign custom name 79 00:03:16,409 --> 00:03:18,989 to the container. Recap that by 80 00:03:18,989 --> 00:03:20,939 default Docker assigns randomly 81 00:03:20,939 --> 00:03:23,339 generated name to a container. And 82 00:03:23,339 --> 00:03:25,829 now let's try to use both options 83 00:03:25,859 --> 00:03:28,769 '--name', and '-h 84 00:03:28,799 --> 00:03:31,439 hostname', and assign custom names, 85 00:03:31,469 --> 00:03:33,929 hostname, and the container name to 86 00:03:33,959 --> 00:03:36,299 those busybox containers, and verify 87 00:03:36,449 --> 00:03:38,369 whether something will change and 88 00:03:38,399 --> 00:03:40,679 whether we will be able to connect 89 00:03:40,679 --> 00:03:42,659 ping one container from another 90 00:03:42,659 --> 00:03:44,399 using either container name 91 00:03:44,520 --> 00:03:46,830 or hostname on that. Let's do that. 92 00:03:47,130 --> 00:03:48,840 Let me clear terminal, and here will 93 00:03:48,840 --> 00:03:53,250 be busybox1, 'docker run -it', 94 00:03:53,580 --> 00:03:55,210 let's use first option 95 00:03:55,210 --> 00:03:58,440 '--name', here let's name it 96 00:03:58,440 --> 00:04:02,100 'busybox1'; and next let's use 97 00:04:02,100 --> 00:04:05,600 '-h' option, it stands for 'hostname', and 98 00:04:05,670 --> 00:04:07,560 here let's say I'll use hostname 99 00:04:07,590 --> 00:04:10,920 'busybox-one'. I have used 100 00:04:10,950 --> 00:04:12,300 different names in order to 101 00:04:12,300 --> 00:04:14,430 distinguish between hostname and 102 00:04:14,430 --> 00:04:16,440 the name of the container. And 103 00:04:16,440 --> 00:04:18,000 finally let's use the name of the 104 00:04:18,029 --> 00:04:20,399 image, it is 'busybox'. Let's press 105 00:04:20,399 --> 00:04:22,709 Enter, and now we are in sh shell, 106 00:04:22,800 --> 00:04:24,360 instead of this busybox1 107 00:04:24,360 --> 00:04:26,190 container; and if I'll enter our 108 00:04:26,190 --> 00:04:30,075 'hostname', I should see 'busybox-one'; 109 00:04:30,075 --> 00:04:33,275 and if I'll enter 'hostname -i', 110 00:04:33,275 --> 00:04:35,790 'hostname -i', I should 111 00:04:35,790 --> 00:04:38,460 see IP address of this busybox1 112 00:04:38,460 --> 00:04:40,560 container. Let's do the same, and 113 00:04:40,560 --> 00:04:43,140 let's create in similar way second 114 00:04:43,170 --> 00:04:45,420 busybox2 container. Let's do that 115 00:04:45,420 --> 00:04:49,394 here. 'docker run -it --name', 116 00:04:49,394 --> 00:04:51,480 name will be busybox2, 117 00:04:51,690 --> 00:04:55,811 and hostname will be busybox-two, 118 00:04:55,811 --> 00:04:56,850 and here will be the 119 00:04:56,850 --> 00:04:59,430 name of the image busybox. Let's 120 00:04:59,430 --> 00:05:01,740 press Enter, and we are now in sh 121 00:05:01,740 --> 00:05:03,660 shell here in the second container. 122 00:05:03,780 --> 00:05:07,020 'hostname' will provide us hostname 123 00:05:07,050 --> 00:05:09,060 of the second container, 'busybox- 124 00:05:09,060 --> 00:05:11,640 two', and 'hostname -i' will 125 00:05:11,640 --> 00:05:13,380 provide us IP address of this 126 00:05:13,380 --> 00:05:15,810 container. Let's as before try to 127 00:05:15,810 --> 00:05:18,210 ping first busybox container 128 00:05:18,210 --> 00:05:20,430 using its IP address, this one in 129 00:05:20,430 --> 00:05:22,140 order to verify connection between 130 00:05:22,140 --> 00:05:26,790 those two containers. 'ping 172.17.0.2', 131 00:05:27,330 --> 00:05:29,970 I'll get response of course. But if 132 00:05:29,970 --> 00:05:33,720 I try to ping by hostname 'busybox 133 00:05:33,750 --> 00:05:36,660 -one', I'll get, bad address 134 00:05:36,720 --> 00:05:40,050 'busybox-one'. Same response I'll get 135 00:05:40,080 --> 00:05:42,840 if I try to ping by using name of 136 00:05:42,840 --> 00:05:45,790 this container. Its name is 'busybox1'. 137 00:05:45,790 --> 00:05:50,031 Let's do that, 'ping busybox1', 138 00:05:50,031 --> 00:05:52,410 like so; and again, bad address 139 00:05:52,440 --> 00:05:55,050 'busybox1'. If I will go to this 140 00:05:55,050 --> 00:05:57,510 last step, and enter here again, 141 00:05:57,540 --> 00:06:00,450 'docker ps'; and afterwards, enter 142 00:06:00,600 --> 00:06:04,290 'docker inspect'. 'docker inspect'; and 143 00:06:04,290 --> 00:06:06,330 here let's inspect busybox1 144 00:06:06,330 --> 00:06:08,130 container. By the way, notice here 145 00:06:08,130 --> 00:06:10,080 custom names that were assigned to 146 00:06:10,080 --> 00:06:11,700 those two containers. And that's 147 00:06:11,700 --> 00:06:13,571 because we have used '--name' 148 00:06:13,571 --> 00:06:15,300 option when we have started 149 00:06:15,300 --> 00:06:16,800 those two containers. And here 150 00:06:16,800 --> 00:06:18,981 let's inspect for example 'busybox1', 151 00:06:18,981 --> 00:06:20,820 'busybox1'. I could use 152 00:06:20,850 --> 00:06:23,430 either name or ID of the container. 153 00:06:23,880 --> 00:06:26,490 Let's press Enter. And I see IP 154 00:06:26,490 --> 00:06:28,050 address of this container. But 155 00:06:28,110 --> 00:06:30,870 Aliases is still set to null. If I 156 00:06:30,870 --> 00:06:32,920 will go to this first step, and try 157 00:06:32,920 --> 00:06:34,620 to perform same action as we 158 00:06:34,620 --> 00:06:37,080 tried on busybox2, for example, 159 00:06:37,100 --> 00:06:40,200 'ping busybox2', or 160 00:06:40,200 --> 00:06:44,700 'ping busybox-two', I'll get same 161 00:06:44,730 --> 00:06:47,160 response, bad address. And the 162 00:06:47,160 --> 00:06:49,410 reason for that is that by default 163 00:06:49,530 --> 00:06:52,080 in default bridge network you 164 00:06:52,080 --> 00:06:53,880 are not able to communicate between 165 00:06:53,880 --> 00:06:56,070 different containers using their 166 00:06:56,100 --> 00:06:59,100 names, or hostnames, that is the 167 00:06:59,100 --> 00:07:01,050 rule in Docker. I don't know 168 00:07:01,050 --> 00:07:02,250 whether it will change in the 169 00:07:02,250 --> 00:07:04,050 future or not. But at the moment, 170 00:07:04,080 --> 00:07:06,870 it is like this. Actually, if you 171 00:07:06,870 --> 00:07:08,250 want to perform communication 172 00:07:08,250 --> 00:07:10,740 between containers using their names, 173 00:07:10,920 --> 00:07:12,960 you need to create first custom 174 00:07:12,990 --> 00:07:15,540 bridge network, and then create 175 00:07:15,540 --> 00:07:17,940 containers inside of that custom 176 00:07:18,000 --> 00:07:20,820 bridge network. And let me next 177 00:07:20,820 --> 00:07:22,590 explain you how you're able to 178 00:07:22,590 --> 00:07:24,210 create custom network using the 179 00:07:24,210 --> 00:07:26,580 Docker, and create new containers 180 00:07:26,610 --> 00:07:28,950 inside of that custom network. I'll 181 00:07:28,950 --> 00:07:30,300 see you next. Bye-Bye. 182 00:07:30,300 --> 00:07:32,821 [no audio]