1 00:00:00,000 --> 00:00:04,300 [Intro Music] 2 00:00:04,350 --> 00:00:05,760 Before creation of multiple 3 00:00:05,760 --> 00:00:07,680 containers based in the same image, 4 00:00:07,800 --> 00:00:09,540 let me briefly explain you what 5 00:00:09,570 --> 00:00:12,510 option '-t' means in 'docker run' 6 00:00:12,510 --> 00:00:14,340 command. Basically, in one of the 7 00:00:14,340 --> 00:00:15,630 previous lectures in multiple 8 00:00:15,630 --> 00:00:17,640 actually, we have used this option, 9 00:00:17,640 --> 00:00:19,380 but I have not yet explained you what 10 00:00:19,380 --> 00:00:21,960 it means. Let me first type here, 11 00:00:21,990 --> 00:00:25,710 'docker run --help'; and here 12 00:00:25,710 --> 00:00:27,480 you'll see this option on the list. 13 00:00:27,630 --> 00:00:30,210 You could use either '-t' or 14 00:00:30,240 --> 00:00:32,711 '--tty'; and it 15 00:00:32,711 --> 00:00:35,880 allocates a pseudo-TTY. I'll explain you 16 00:00:35,910 --> 00:00:37,590 what it does actually in a minute. 17 00:00:37,860 --> 00:00:40,230 Also, if you scroll up, you'll find 18 00:00:40,260 --> 00:00:43,270 option '-i' or '--interactive'; 19 00:00:43,270 --> 00:00:44,310 and with this option 20 00:00:44,310 --> 00:00:46,500 in place, you will be connected to 21 00:00:46,530 --> 00:00:48,750 'STDIN', standard input, or a 22 00:00:48,750 --> 00:00:50,310 specific process that is running 23 00:00:50,340 --> 00:00:52,500 inside of the container. Okay. 24 00:00:52,740 --> 00:00:54,630 Let's first create container using 25 00:00:54,720 --> 00:00:57,120 only '-i' option. Next, let's 26 00:00:57,120 --> 00:00:59,280 try to use only the '-t' option. 27 00:00:59,280 --> 00:01:01,680 And finally, let's combine '-i' 28 00:01:01,710 --> 00:01:03,570 and '-t' options together. 29 00:01:03,720 --> 00:01:06,810 Okay, let's do that. 'docker run 30 00:01:06,840 --> 00:01:11,460 -i alpine'; and here I am now 31 00:01:11,520 --> 00:01:13,950 attached to 'sh' process inside 32 00:01:13,950 --> 00:01:15,990 of the alpine container; and I'm 33 00:01:16,020 --> 00:01:18,570 able to list files, I'm able to 34 00:01:18,570 --> 00:01:22,800 create new folders, 'mkdir test', 'cd 35 00:01:22,890 --> 00:01:25,590 test'. Next, let's for example, write 36 00:01:25,590 --> 00:01:28,710 some text to the file like, 'echo 37 00:01:30,000 --> 00:01:33,600 'Hello from Alpine'; and let's 38 00:01:33,600 --> 00:01:36,790 write this text to 'file.txt'. 39 00:01:36,790 --> 00:01:39,360 Let's now list the files in the 40 00:01:39,390 --> 00:01:42,120 'test' folder, and we see response 41 00:01:42,120 --> 00:01:44,070 from the process and you see file 42 00:01:44,070 --> 00:01:46,440 name file.txt. And now let's 43 00:01:46,440 --> 00:01:48,210 read the contents of this file, 'cat 44 00:01:48,240 --> 00:01:50,850 file.txt', and I should see 'Hello 45 00:01:50,850 --> 00:01:53,040 from Alpine'. And yes, I see this 46 00:01:53,040 --> 00:01:55,590 result. But as you see here, when 47 00:01:55,590 --> 00:01:58,080 we use only '-i' option, we don't 48 00:01:58,080 --> 00:02:00,420 see any command prompt, we don't see 49 00:02:00,450 --> 00:02:02,460 any formatting of the output and so 50 00:02:02,460 --> 00:02:05,171 on. That's why with option '-t' 51 00:02:05,171 --> 00:02:07,230 Docker is able to create for 52 00:02:07,230 --> 00:02:10,380 you, pseudo-TTY; and it will 53 00:02:10,380 --> 00:02:12,960 actually produce some nice looking 54 00:02:12,960 --> 00:02:15,330 command prompt, format results, 55 00:02:15,330 --> 00:02:17,820 and so on. Let's try that. I could 56 00:02:17,820 --> 00:02:20,730 try to terminate this process using 57 00:02:20,730 --> 00:02:23,580 Ctrl+C, but it will not work. And 58 00:02:23,610 --> 00:02:25,170 you know why is that, because this 59 00:02:25,170 --> 00:02:27,270 process, 'sh' process inside of this 60 00:02:27,270 --> 00:02:29,970 container does not accept such 61 00:02:29,970 --> 00:02:32,070 commands. That's why you are able 62 00:02:32,070 --> 00:02:34,680 either to stop container, or kill it, or 63 00:02:34,710 --> 00:02:36,990 you are able to use 'exit' command 64 00:02:37,020 --> 00:02:39,180 inside of this 'sh' terminal that 65 00:02:39,180 --> 00:02:41,910 will exit from 'sh' process. And of 66 00:02:41,910 --> 00:02:43,890 course container will be terminated 67 00:02:43,890 --> 00:02:46,020 after that. Let's try that, 'exit'. 68 00:02:46,230 --> 00:02:48,720 And yes, we were exited from 'sh' 69 00:02:48,720 --> 00:02:50,640 process and if I list 70 00:02:50,670 --> 00:02:53,520 containers now, 'docker ps', I will see 71 00:02:53,520 --> 00:02:55,050 empty output, there are no 72 00:02:55,050 --> 00:02:57,600 containers currently running. Now, 73 00:02:57,600 --> 00:02:59,580 let's try to create same container 74 00:02:59,580 --> 00:03:01,860 based on alpine image, but now using 75 00:03:01,980 --> 00:03:04,560 only '-t' option. Let's do so. 76 00:03:04,860 --> 00:03:08,130 Let's clear terminal, 'docker run 77 00:03:08,200 --> 00:03:10,100 -t alpine', 78 00:03:10,100 --> 00:03:12,200 [no audio] 79 00:03:12,270 --> 00:03:14,220 and I actually see command prompt, 80 00:03:14,340 --> 00:03:16,950 but I am not able to enter any 81 00:03:16,950 --> 00:03:18,810 commands, and they don't get any 82 00:03:18,810 --> 00:03:21,300 results from it. That's because 83 00:03:21,300 --> 00:03:23,220 now I'm not actually connected to 84 00:03:23,220 --> 00:03:26,400 standard in of 'sh' process. That's 85 00:03:26,400 --> 00:03:28,200 why it's not enough to use only 86 00:03:28,200 --> 00:03:29,550 '-t' option that will 87 00:03:29,550 --> 00:03:31,770 emulate pseudo-TTY. You will not be 88 00:03:31,770 --> 00:03:34,170 able to enter any commands, or get 89 00:03:34,200 --> 00:03:36,630 any output from specific process. 90 00:03:37,020 --> 00:03:39,330 Let me exit from this. Actually I'm 91 00:03:39,330 --> 00:03:40,800 not sure whether I will be able to 92 00:03:40,800 --> 00:03:43,140 do so. No, I'm not able to do so. 93 00:03:43,140 --> 00:03:45,030 That's why in this case I need to 94 00:03:45,030 --> 00:03:47,820 terminate container manually. Let's go 95 00:03:47,850 --> 00:03:51,600 to separate tab, 'docker ps' here, and 96 00:03:51,630 --> 00:03:54,510 'docker kill', and ID of the container. 97 00:03:54,900 --> 00:03:56,370 Container was killed and I see 98 00:03:56,370 --> 00:03:59,220 that this first session, this step 99 00:03:59,520 --> 00:04:02,100 'just rang a bell!'. It's funny. Let's go 100 00:04:02,100 --> 00:04:03,960 here, and I see that this process 101 00:04:03,960 --> 00:04:06,450 was terminated. Okay. Let's now 102 00:04:06,450 --> 00:04:08,400 launch same container with alpine 103 00:04:08,400 --> 00:04:10,740 image but now using both options 104 00:04:10,830 --> 00:04:13,740 '-t' and '-i'. Let's clear 105 00:04:13,740 --> 00:04:16,290 terminal, 'docker run', and you are 106 00:04:16,290 --> 00:04:18,189 able to use those two options 107 00:04:18,189 --> 00:04:21,360 '-i' and '-t' separately like so; 108 00:04:21,570 --> 00:04:23,519 or you're able to combine them and 109 00:04:23,519 --> 00:04:26,490 write simply '-it'. Please 110 00:04:26,519 --> 00:04:28,950 remember that now we are using two 111 00:04:28,950 --> 00:04:31,140 different options, not single option 112 00:04:31,140 --> 00:04:33,870 called 'it'. Great. Let's now type 113 00:04:33,870 --> 00:04:35,700 name of the image 'alpine', and press 114 00:04:35,700 --> 00:04:38,130 Enter. And now you see command 115 00:04:38,130 --> 00:04:40,560 prompt. And if I'll 'cd' for example to 116 00:04:40,560 --> 00:04:42,150 'bin', you'll see that this command 117 00:04:42,150 --> 00:04:43,680 prompt will be adjusted 118 00:04:43,710 --> 00:04:46,230 accordingly. If I list files here 119 00:04:46,260 --> 00:04:48,210 in 'bin' folder, you will see that 120 00:04:48,210 --> 00:04:49,740 they were formatted with different 121 00:04:49,740 --> 00:04:51,960 colors and that's thanks to pseudo 122 00:04:51,960 --> 00:04:54,750 TTY. Great. That's how you're able 123 00:04:54,750 --> 00:04:57,030 to get access to specific process 124 00:04:57,090 --> 00:05:00,460 using pseudo-TTY, and 'interactive' option. 125 00:05:00,460 --> 00:05:02,040 That will actually connect you 126 00:05:02,070 --> 00:05:03,750 to standard input and standard 127 00:05:03,780 --> 00:05:05,910 output of specific process. In our 128 00:05:05,910 --> 00:05:08,070 case, that was default process 'sh' 129 00:05:08,100 --> 00:05:10,860 shell. Great. Let's now try to 130 00:05:10,860 --> 00:05:12,660 terminate this process using Ctrl+ 131 00:05:12,660 --> 00:05:15,120 C, but it will not work. Reason is 132 00:05:15,120 --> 00:05:16,560 the same as before. I have 133 00:05:16,560 --> 00:05:18,600 explained you that 'sh' process does 134 00:05:18,600 --> 00:05:22,020 not accept any system commands, but 135 00:05:22,020 --> 00:05:23,610 you're able to exit from this 136 00:05:23,610 --> 00:05:26,430 process as from any shell using 137 00:05:26,490 --> 00:05:28,980 'exit' command. Let's type 'exit'. This 138 00:05:29,010 --> 00:05:30,990 'sh' process inside of the container 139 00:05:30,990 --> 00:05:33,390 will be terminated. There will be no 140 00:05:33,450 --> 00:05:35,550 other processes running, and Docker 141 00:05:35,580 --> 00:05:37,470 will therefore terminate this 142 00:05:37,470 --> 00:05:40,320 container. Let's type 'exit', Enter, and 143 00:05:40,350 --> 00:05:41,910 we get back to our terminal 144 00:05:41,910 --> 00:05:45,120 prompt and if I'll list containers 145 00:05:45,120 --> 00:05:47,370 now, 'docker ps', you will see nothing. 146 00:05:47,460 --> 00:05:51,240 Container was exited. Great. That 147 00:05:51,240 --> 00:05:53,020 is the difference between '-i', 148 00:05:53,020 --> 00:05:56,100 '-t', and '-i -t' options. 149 00:05:56,880 --> 00:05:58,950 Let's now try to do the same with 150 00:05:58,950 --> 00:06:00,990 for example ubuntu image. Let's 151 00:06:00,990 --> 00:06:03,900 clear terminal, and type 'docker run 152 00:06:04,050 --> 00:06:07,530 -it ubuntu. Recap that ubuntu is 153 00:06:07,530 --> 00:06:09,570 already present in our local images 154 00:06:09,570 --> 00:06:13,320 cache. Container was created, and we 155 00:06:13,320 --> 00:06:16,500 were logged in as root user. And 156 00:06:16,500 --> 00:06:19,140 recap the in Ubuntu default command 157 00:06:19,170 --> 00:06:21,600 is actually '/bin/bash'. Let me 158 00:06:21,600 --> 00:06:23,160 list containers now. And here 159 00:06:23,160 --> 00:06:25,620 you see this command, '/bin/bash'. This 160 00:06:25,620 --> 00:06:27,330 is actually shell but it differs 161 00:06:27,330 --> 00:06:29,790 from this 'sh' shell. That's why here 162 00:06:29,790 --> 00:06:31,380 in this step, you'll see another 163 00:06:31,410 --> 00:06:33,840 command prompt and it includes user 164 00:06:33,840 --> 00:06:36,090 name and host name of this ubuntu 165 00:06:36,090 --> 00:06:38,610 container. If I list files, I will 166 00:06:38,610 --> 00:06:41,010 get a similar result and if I'll 167 00:06:41,010 --> 00:06:43,170 'cd' for example to 'bin', list files 168 00:06:43,170 --> 00:06:45,780 here, I get similar output same as I 169 00:06:45,780 --> 00:06:48,810 have seen in 'sh' shell. Let's also 170 00:06:48,810 --> 00:06:50,970 try to terminate this process using 171 00:06:51,000 --> 00:06:53,910 Ctrl+C, also same result, but you 172 00:06:53,910 --> 00:06:55,710 are able again to exit from this 173 00:06:55,710 --> 00:06:57,960 process, in this case 'bash' process 174 00:06:57,960 --> 00:07:01,170 using 'exit' command. And now process 175 00:07:01,170 --> 00:07:03,750 was terminated, and container was 176 00:07:03,780 --> 00:07:06,060 deleted as well. Let's verify that, 177 00:07:06,150 --> 00:07:08,220 'docker ps', and now there are no 178 00:07:08,220 --> 00:07:10,500 containers currently running. That's 179 00:07:10,500 --> 00:07:12,300 all about '-t' option that 180 00:07:12,300 --> 00:07:13,710 you could use with 'docker run' 181 00:07:13,710 --> 00:07:15,690 command. And in most cases it is 182 00:07:15,690 --> 00:07:18,720 used along with '-i' option. And those 183 00:07:18,720 --> 00:07:20,340 options could be combined and you 184 00:07:20,340 --> 00:07:22,869 could write simply '-it'. '-t' 185 00:07:22,869 --> 00:07:25,110 option creates pseudo-TTY that 186 00:07:25,110 --> 00:07:26,700 allows you to interact with 187 00:07:26,700 --> 00:07:28,050 specific process inside of the 188 00:07:28,050 --> 00:07:30,060 container. That's all for this 189 00:07:30,060 --> 00:07:32,010 lecture. And in the next one let 190 00:07:32,010 --> 00:07:34,620 me create multiple containers based 191 00:07:34,620 --> 00:07:36,420 on the same image. I'll see you 192 00:07:36,420 --> 00:07:37,400 next. Bye-Bye. 193 00:07:37,400 --> 00:07:39,562 [no audio]