1 00:00:00,000 --> 00:00:04,300 [Intro Music] 2 00:00:04,380 --> 00:00:06,480 Our goal at the moment is to 3 00:00:06,510 --> 00:00:08,250 establish communication between two 4 00:00:08,250 --> 00:00:10,350 containers. And we will start 5 00:00:10,380 --> 00:00:12,240 simple and I'll explain you how 6 00:00:12,240 --> 00:00:14,250 you're able to ping one container 7 00:00:14,250 --> 00:00:16,140 from another in default bridge 8 00:00:16,140 --> 00:00:18,120 network. And for that, we will 9 00:00:18,120 --> 00:00:20,520 create two busybox containers. 10 00:00:20,880 --> 00:00:22,440 At the moment there was a 'wordpress' 11 00:00:22,440 --> 00:00:24,150 container running and it is 12 00:00:24,150 --> 00:00:26,310 completely safe to stop it and 13 00:00:26,340 --> 00:00:28,380 remove at the moment. But no 14 00:00:28,380 --> 00:00:29,550 worries, we will get back to 15 00:00:29,550 --> 00:00:31,290 'wordpress' container a bit later. 16 00:00:31,620 --> 00:00:33,810 All right, let me stop this 17 00:00:33,810 --> 00:00:37,200 container 'docker stop 75', 18 00:00:37,200 --> 00:00:40,800 [no audio] 19 00:00:40,890 --> 00:00:43,560 and let's prune all stopped containers 20 00:00:43,620 --> 00:00:50,310 'docker container prune'. Yes. And all 21 00:00:50,310 --> 00:00:52,860 containers were removed. Wonderful. 22 00:00:53,040 --> 00:00:54,780 Let's now create two busybox 23 00:00:54,780 --> 00:00:56,550 containers. Here in this step will 24 00:00:56,550 --> 00:00:58,560 be first one and in another tab we 25 00:00:58,560 --> 00:01:00,810 will create second one. Great. 26 00:01:00,840 --> 00:01:02,850 Let's use 'docker run' command. Recap 27 00:01:02,850 --> 00:01:04,739 that 'busybox' image is already 28 00:01:04,739 --> 00:01:06,780 in our local cache. 'docker run', 29 00:01:06,840 --> 00:01:09,960 I'll use two options '-it'; and 30 00:01:09,960 --> 00:01:14,370 here will be 'busybox', like so. And 31 00:01:14,400 --> 00:01:17,340 in another tab let's also start 32 00:01:17,370 --> 00:01:20,160 one more 'busybox' container 'docker 33 00:01:21,420 --> 00:01:26,010 run -it busybox'. Great. We have 34 00:01:26,010 --> 00:01:28,770 logged into 'sh' shell here in this 35 00:01:28,770 --> 00:01:30,780 container, and in this container. And 36 00:01:30,780 --> 00:01:33,150 now let's verify which IP addresses 37 00:01:33,180 --> 00:01:35,700 were assigned to those containers. 38 00:01:35,880 --> 00:01:37,260 For that you could use command 39 00:01:37,260 --> 00:01:40,800 'hostname -i'; and here let's 40 00:01:40,830 --> 00:01:42,270 enter this command as well, 41 00:01:42,630 --> 00:01:45,420 'hostname -i', and you see that 42 00:01:45,450 --> 00:01:47,340 the IP addresses that were assigned 43 00:01:47,340 --> 00:01:49,260 to those containers are different. 44 00:01:49,320 --> 00:01:51,300 Here you see that this address ends 45 00:01:51,300 --> 00:01:53,850 with 2, and here this address 46 00:01:53,880 --> 00:01:56,160 ends with 3. But you may notice 47 00:01:56,160 --> 00:01:58,350 that those IP addresses are from 48 00:01:58,350 --> 00:02:00,510 the same sub-network. It is 49 00:02:00,510 --> 00:02:03,480 basically Private Sub-network 50 00:02:03,600 --> 00:02:08,340 called 172.17.0.0 with subnet 51 00:02:08,340 --> 00:02:11,970 mask 16. And those IP addresses 52 00:02:12,000 --> 00:02:13,979 from this range are used for 53 00:02:13,979 --> 00:02:15,690 assignment to containers by 54 00:02:15,690 --> 00:02:17,790 default, it is actually default 55 00:02:17,820 --> 00:02:20,280 network. And let's now verify 56 00:02:20,310 --> 00:02:22,590 whether those containers are able 57 00:02:22,590 --> 00:02:24,060 to communicate between each other 58 00:02:24,090 --> 00:02:25,710 or not. And for that, we will 59 00:02:25,710 --> 00:02:28,020 simply use ping utility that will 60 00:02:28,020 --> 00:02:30,750 perform a connection test from one 61 00:02:30,750 --> 00:02:33,030 IP address to another. And from 62 00:02:33,030 --> 00:02:35,415 this 'busybox' container, we could ping 63 00:02:35,415 --> 00:02:37,110 another IP address of another 64 00:02:37,110 --> 00:02:39,510 container using ping utility. This 65 00:02:39,510 --> 00:02:41,310 utility is available in 'busybox' 66 00:02:41,310 --> 00:02:43,470 container out of the box. Let's use 67 00:02:43,470 --> 00:02:48,840 it, 'ping 172.17.0.3', and you see 68 00:02:48,870 --> 00:02:51,150 that we get response from another 69 00:02:51,150 --> 00:02:53,190 container. And that means that 70 00:02:53,220 --> 00:02:55,470 there is connection between two 71 00:02:55,470 --> 00:02:57,420 containers and they are able to 72 00:02:57,420 --> 00:03:00,060 communicate over any TCP or UDP 73 00:03:00,060 --> 00:03:02,460 ports, because this ping utility 74 00:03:02,580 --> 00:03:05,400 works on the third level of the OSI 75 00:03:05,400 --> 00:03:08,190 model, and it means that all levels 76 00:03:08,220 --> 00:03:10,800 up will work as well. No worries, 77 00:03:10,800 --> 00:03:12,540 we'll get back to network concepts 78 00:03:12,540 --> 00:03:14,070 a bit later in the course, and I'll 79 00:03:14,070 --> 00:03:16,170 explain you all of that in details. 80 00:03:16,380 --> 00:03:18,330 For now you need to understand that 81 00:03:18,570 --> 00:03:20,490 those containers are able to 82 00:03:20,490 --> 00:03:23,400 communicate over any TCP or UDP 83 00:03:23,400 --> 00:03:26,010 ports. Wonderful. Also, you're able 84 00:03:26,010 --> 00:03:27,990 to verify connection from this 85 00:03:27,990 --> 00:03:30,030 container, and here you're able to 86 00:03:30,030 --> 00:03:31,350 use the same command 'ping 87 00:03:31,410 --> 00:03:36,660 172.17.0.2, and you of course will 88 00:03:36,660 --> 00:03:39,120 get response from this 'busybox' 89 00:03:39,120 --> 00:03:42,120 container. Great. That's how IP 90 00:03:42,120 --> 00:03:44,040 addresses are assigned by default 91 00:03:44,070 --> 00:03:46,680 containers and how you're able to 92 00:03:46,680 --> 00:03:48,600 communicate between containers by 93 00:03:48,600 --> 00:03:50,580 default in default bridge network. 94 00:03:51,030 --> 00:03:53,070 Also you are able to verify which 95 00:03:53,100 --> 00:03:55,320 IP address was assigned to specific 96 00:03:55,320 --> 00:03:57,150 container by using the command 97 00:03:57,180 --> 00:03:58,350 'docker inspect'. 98 00:03:58,589 --> 00:04:01,049 Let me open up a new tab here, and 99 00:04:01,109 --> 00:04:03,479 first let's enter 'docker ps', and 100 00:04:03,479 --> 00:04:05,609 you'll see two containers running. 101 00:04:05,639 --> 00:04:07,619 Here is the first ID and here is the second 102 00:04:07,619 --> 00:04:10,139 ID. And now let's use 'docker inspect' 103 00:04:10,139 --> 00:04:13,469 command, 'docker inspect', and pass 104 00:04:13,469 --> 00:04:15,629 here ID of any of the containers. 105 00:04:15,809 --> 00:04:17,548 Let's use this ID. Let me copy it, 106 00:04:17,548 --> 00:04:20,488 paste here. And you'll see IP 107 00:04:20,488 --> 00:04:22,529 address almost at the end of this 108 00:04:22,529 --> 00:04:24,119 output. Here is the IP address 109 00:04:24,149 --> 00:04:27,059 assigned to this 'busybox' container. 110 00:04:27,418 --> 00:04:29,309 And if you'll verify the details 111 00:04:29,309 --> 00:04:31,439 about another container, let me do 112 00:04:31,439 --> 00:04:35,189 so, 'docker ps', 'docker inspect', and 113 00:04:35,219 --> 00:04:38,249 let's use ID this one, copy it, 114 00:04:38,249 --> 00:04:40,709 paste here, you'll see another IP 115 00:04:40,709 --> 00:04:42,689 address assigned to this container. 116 00:04:43,019 --> 00:04:44,819 You may also notice that there was 117 00:04:44,849 --> 00:04:47,549 Gateway setting and it is equal for 118 00:04:47,549 --> 00:04:49,739 both containers. It is actually 119 00:04:49,799 --> 00:04:52,079 virtual IP address located at the 120 00:04:52,079 --> 00:04:54,359 Docker Host, and it acts as a 121 00:04:54,359 --> 00:04:57,119 default gateway for all containers 122 00:04:57,149 --> 00:04:58,979 that are running in default bridge 123 00:04:58,979 --> 00:05:01,109 network. Wonderful. These aer 124 00:05:01,379 --> 00:05:04,799 fundamentals of IP networking, by 125 00:05:04,799 --> 00:05:07,049 default in Docker. Again, here was 126 00:05:07,079 --> 00:05:11,279 default network 172.17.0.0, and 127 00:05:11,279 --> 00:05:13,600 subnet mask is 16. Here you see 128 00:05:13,600 --> 00:05:16,300 'IPPrefixLen' as third line 129 00:05:16,319 --> 00:05:18,449 here in this output. And that means 130 00:05:18,479 --> 00:05:20,969 that you may see IP addresses like 131 00:05:20,969 --> 00:05:28,049 172.17.5.6, or 100.7, or like in this 132 00:05:28,049 --> 00:05:32,729 case 172.17.0.2, 5, 10, and so on. But 133 00:05:32,759 --> 00:05:35,249 this part will be the same for all 134 00:05:35,279 --> 00:05:37,799 IP addresses, it is prefix. All 135 00:05:37,799 --> 00:05:39,539 right, that's the basics of IP 136 00:05:39,539 --> 00:05:41,669 networking between containers that 137 00:05:41,699 --> 00:05:43,499 are created in Docker by default. 138 00:05:43,799 --> 00:05:45,959 Also let me demonstrate to you that you 139 00:05:45,959 --> 00:05:49,019 are able to connect to any IP 140 00:05:49,019 --> 00:05:51,659 address or hostname in internet 141 00:05:51,689 --> 00:05:53,699 from container. And for that you 142 00:05:53,699 --> 00:05:55,769 could use same command ping and for 143 00:05:55,769 --> 00:05:59,549 example, type 'ping google.com', and 144 00:05:59,549 --> 00:06:01,139 you'll get response from Google, 145 00:06:01,259 --> 00:06:03,059 you will get response actually from 146 00:06:03,149 --> 00:06:05,549 IP address of one of the Google's 147 00:06:05,579 --> 00:06:08,369 servers. Great. That's all what I 148 00:06:08,369 --> 00:06:09,749 wanted to show you here in this 149 00:06:09,749 --> 00:06:11,939 lecture. And the most important 150 00:06:11,969 --> 00:06:13,679 outcome is that containers by 151 00:06:13,679 --> 00:06:15,389 default may communicate between 152 00:06:15,389 --> 00:06:17,489 each other using IP addresses. 153 00:06:18,209 --> 00:06:19,979 Wonderful. Let's now proceed and 154 00:06:19,979 --> 00:06:22,709 next let's try to create mysql 155 00:06:22,709 --> 00:06:24,929 container, and see whether we will 156 00:06:24,929 --> 00:06:26,909 be able to start it without any 157 00:06:26,939 --> 00:06:29,800 options or not. I'll see you next. Bye-Bye. 158 00:06:29,800 --> 00:06:31,957 [no audio]