1 00:00:00,000 --> 00:00:04,000 [Intro Music] 2 00:00:04,080 --> 00:00:06,090 I have just explained to you what is 3 00:00:06,090 --> 00:00:08,250 default bridge network. And you 4 00:00:08,250 --> 00:00:10,080 will now understand that containers 5 00:00:10,140 --> 00:00:11,790 may communicate between each other 6 00:00:11,850 --> 00:00:13,980 using own IP addresses assigned 7 00:00:13,980 --> 00:00:16,920 randomly by Docker host. And we have 8 00:00:16,920 --> 00:00:19,020 verified that using two busybox 9 00:00:19,020 --> 00:00:21,660 containers. Next important concept 10 00:00:21,690 --> 00:00:23,940 is environment variable. Let me 11 00:00:23,940 --> 00:00:25,410 explain first what is an 12 00:00:25,410 --> 00:00:26,670 environment variable, and 13 00:00:26,670 --> 00:00:28,260 afterwards I'll explain you how 14 00:00:28,260 --> 00:00:29,970 you're able to set custom 15 00:00:30,000 --> 00:00:31,950 environment variable for specific 16 00:00:31,950 --> 00:00:34,740 container. Great. We are now still 17 00:00:34,770 --> 00:00:37,170 running two busybox containers. Let me 18 00:00:37,170 --> 00:00:38,820 clear terminal in one of them, 19 00:00:39,030 --> 00:00:42,072 and here simply type command 'env' 20 00:00:42,072 --> 00:00:44,580 like so, and you'll get a list 21 00:00:44,640 --> 00:00:47,460 of let's say key-value pairs. Here 22 00:00:47,460 --> 00:00:49,920 are keys or names of environment 23 00:00:49,920 --> 00:00:53,610 variables - HOSTNAME, SHLVL, HOME, 24 00:00:53,700 --> 00:00:57,570 TERM, PATH, and PWD. And that's our 25 00:00:57,630 --> 00:01:00,660 default variables that are set out 26 00:01:00,660 --> 00:01:03,030 of the box for every busybox 27 00:01:03,030 --> 00:01:05,340 container. And again, set of 28 00:01:05,340 --> 00:01:07,230 environment variables is different 29 00:01:07,260 --> 00:01:09,690 for different containers. And we 30 00:01:09,690 --> 00:01:11,820 could easily verify that. Let's in 31 00:01:11,820 --> 00:01:13,500 another step launch another 32 00:01:13,500 --> 00:01:15,060 container, for example, ubuntu 33 00:01:15,060 --> 00:01:18,270 container. 'docker run -it 34 00:01:18,870 --> 00:01:23,010 ubuntu', and let's type 'env' here, 35 00:01:23,430 --> 00:01:25,860 and you'll see a bunch of different 36 00:01:25,860 --> 00:01:28,380 environment variables that were set 37 00:01:28,470 --> 00:01:30,900 for this specific container. For 38 00:01:30,900 --> 00:01:33,210 example, you see here a variable 39 00:01:33,210 --> 00:01:36,120 called LS_COLORS, or 40 00:01:36,150 --> 00:01:38,400 you see another HOSTNAME variable, 41 00:01:38,400 --> 00:01:40,350 it is actually the same variable as 42 00:01:40,350 --> 00:01:42,600 was set for those containers, but 43 00:01:42,600 --> 00:01:44,160 HOSTNAME here is different, of 44 00:01:44,160 --> 00:01:47,040 course, from this HOSTNAME. Also, 45 00:01:47,040 --> 00:01:48,960 you may see that such variables 46 00:01:48,960 --> 00:01:52,350 as PWD, HOME, are the same for 47 00:01:52,380 --> 00:01:54,750 this container and this container. 48 00:01:55,590 --> 00:01:57,690 But again, those variables are set 49 00:01:57,690 --> 00:01:59,460 for each specific container 50 00:01:59,550 --> 00:02:02,250 individually. Also, you are able to 51 00:02:02,250 --> 00:02:03,810 verify environment variables 52 00:02:03,840 --> 00:02:07,020 without logging into 'sh' or 'bash' 53 00:02:07,020 --> 00:02:09,360 shell by doing following. Let me 54 00:02:09,389 --> 00:02:12,780 go out from this container, clear 55 00:02:12,780 --> 00:02:15,150 terminal, let's list the containers 56 00:02:15,180 --> 00:02:16,500 that are currently running. There 57 00:02:16,500 --> 00:02:18,780 are two busybox containers. And you 58 00:02:18,780 --> 00:02:21,330 are able to use 'exec' command in 59 00:02:21,330 --> 00:02:24,360 order to execute 'env' command inside 60 00:02:24,360 --> 00:02:26,190 of the container. Let's do so. 61 00:02:26,370 --> 00:02:29,550 'docker exec', and here will be ID of 62 00:02:29,550 --> 00:02:30,990 the container, for example, this 63 00:02:30,990 --> 00:02:33,690 one, 'a5', and next type 'env', 64 00:02:33,960 --> 00:02:35,820 again here is command that will 65 00:02:35,820 --> 00:02:37,980 override default command, and we 66 00:02:37,980 --> 00:02:39,810 will actually create additional 67 00:02:39,810 --> 00:02:41,700 process that will be executed 68 00:02:41,700 --> 00:02:43,380 inside of specific container with 69 00:02:43,380 --> 00:02:45,840 specific ID. Let's press Enter, and 70 00:02:45,840 --> 00:02:47,130 you'll also see environment 71 00:02:47,130 --> 00:02:49,140 variables. But notice that with 72 00:02:49,140 --> 00:02:50,850 this command, you'll see less 73 00:02:50,880 --> 00:02:52,950 environment variables than in this 74 00:02:52,950 --> 00:02:55,020 case, because in this case, we are 75 00:02:55,020 --> 00:02:56,730 looking at environment variables 76 00:02:56,760 --> 00:02:59,280 inside of the 'sh' shell that 77 00:02:59,310 --> 00:03:01,290 actually added some additional 78 00:03:01,290 --> 00:03:03,120 environment variables when we have 79 00:03:03,120 --> 00:03:05,790 logged into 'sh' shell. That's the 80 00:03:05,790 --> 00:03:07,800 reason why here was set of 81 00:03:07,860 --> 00:03:09,390 environment variables that is 82 00:03:09,420 --> 00:03:12,180 larger than here. Wonderful. But 83 00:03:12,210 --> 00:03:14,040 what is the essence actually of using 84 00:03:14,070 --> 00:03:16,230 those environment variables? Very 85 00:03:16,230 --> 00:03:18,450 often applications require some 86 00:03:18,480 --> 00:03:21,060 initial setting parameters, like 87 00:03:21,090 --> 00:03:23,220 password, the username or some 88 00:03:23,220 --> 00:03:24,690 connection details or something 89 00:03:24,690 --> 00:03:27,450 else. And you are able to set those 90 00:03:27,450 --> 00:03:29,340 values before the start of the 91 00:03:29,340 --> 00:03:31,620 application. For example, let's say 92 00:03:31,620 --> 00:03:33,690 that your application needs to 93 00:03:33,690 --> 00:03:36,720 connect to some external server and 94 00:03:36,720 --> 00:03:38,550 for that it needs to use 95 00:03:38,550 --> 00:03:40,260 credentials - username and password. 96 00:03:40,680 --> 00:03:42,870 And it is not safe to store this 97 00:03:42,870 --> 00:03:44,850 username and password inside of the 98 00:03:44,880 --> 00:03:47,280 application files. It is not safe 99 00:03:47,280 --> 00:03:49,410 at all, because anyone else may 100 00:03:49,440 --> 00:03:51,120 easily read this username and 101 00:03:51,120 --> 00:03:52,650 password and use for its own 102 00:03:52,650 --> 00:03:54,990 purposes. That's why you are able 103 00:03:55,020 --> 00:03:58,110 to initialize those parameters, 104 00:03:58,140 --> 00:03:59,790 username and password when 105 00:03:59,880 --> 00:04:01,950 application is started. And you are 106 00:04:01,950 --> 00:04:03,510 able to use for that environment 107 00:04:03,510 --> 00:04:05,970 variables. Also you are able to 108 00:04:06,000 --> 00:04:08,190 override any default environment 109 00:04:08,190 --> 00:04:10,440 variables if you want. Again, it's 110 00:04:10,440 --> 00:04:12,060 a pretty common concept to use 111 00:04:12,090 --> 00:04:13,740 environment variables in different 112 00:04:13,740 --> 00:04:16,290 applications. And we will use those 113 00:04:16,290 --> 00:04:18,209 variables multiple times throughout 114 00:04:18,209 --> 00:04:20,040 this course. For now, that's all 115 00:04:20,040 --> 00:04:21,990 for this lecture. And let's proceed 116 00:04:22,019 --> 00:04:23,880 and next as promised, let's create 117 00:04:23,910 --> 00:04:26,610 mysql container and see whether it 118 00:04:26,610 --> 00:04:28,260 will be started or not by default 119 00:04:28,260 --> 00:04:29,760 without any additional 120 00:04:29,760 --> 00:04:31,350 environmental variables. I will see 121 00:04:31,350 --> 00:04:32,310 you next. Bye-Bye. 122 00:04:32,310 --> 00:04:34,858 [no audio]