1 00:00:00,000 --> 00:00:04,200 [Intro Music] 2 00:00:04,290 --> 00:00:06,300 Okay guys, so we have just created a 3 00:00:06,300 --> 00:00:08,250 very first container using a 4 00:00:08,250 --> 00:00:10,680 hello-world image. We have pulled 5 00:00:10,680 --> 00:00:12,870 it from a Remote Registry called 6 00:00:12,870 --> 00:00:14,910 Docker Hub and afterwards I have 7 00:00:14,910 --> 00:00:16,290 created container and this 8 00:00:16,290 --> 00:00:18,450 container has printed some text to 9 00:00:18,450 --> 00:00:21,030 the terminal. Also in this text 10 00:00:21,030 --> 00:00:23,500 you see suggestion to try another 11 00:00:23,500 --> 00:00:25,400 container with this command 12 00:00:25,500 --> 00:00:29,070 'docker run -it ubuntu bash'. And 13 00:00:29,070 --> 00:00:31,230 with this command we will be able 14 00:00:31,230 --> 00:00:33,570 to create another container using 15 00:00:33,630 --> 00:00:36,510 ubuntu image. But let's try it 16 00:00:36,540 --> 00:00:39,660 without option '-it', and 'bash'. 17 00:00:39,660 --> 00:00:42,270 Simply as we have tried with 18 00:00:42,480 --> 00:00:44,880 'docker run hello-world'. Let's now 19 00:00:44,880 --> 00:00:47,070 type 'docker run ubuntu', and that's 20 00:00:47,100 --> 00:00:49,320 it, and let's see what will happen. Let me 21 00:00:49,320 --> 00:00:51,750 clear terminal, 'Ctrl+K', and here 22 00:00:51,780 --> 00:00:54,990 let me type 'docker run ubuntu'. 23 00:00:55,650 --> 00:00:58,020 You see that we again we are not 24 00:00:58,050 --> 00:00:59,910 able to find the image 'ubuntu: 25 00:00:59,910 --> 00:01:02,340 latest' locally. And that's why we 26 00:01:02,340 --> 00:01:04,590 have started pull operation from 27 00:01:04,620 --> 00:01:07,200 Remote Registry Docker Hub and you 28 00:01:07,200 --> 00:01:09,270 see that we have pulled several 29 00:01:09,270 --> 00:01:11,040 times and you see here different 30 00:01:11,040 --> 00:01:13,530 IDs. Now, I will not explain you 31 00:01:13,530 --> 00:01:15,270 what it means. We will get back 32 00:01:15,270 --> 00:01:16,590 to it later on when I will 33 00:01:16,620 --> 00:01:18,600 explain you how Docker works under 34 00:01:18,600 --> 00:01:20,100 the hood. For now, you should 35 00:01:20,100 --> 00:01:21,480 understand that we have simply 36 00:01:21,480 --> 00:01:24,030 pulled image called ubuntu from a 37 00:01:24,030 --> 00:01:26,730 Remote Registry Docker Hub. Also 38 00:01:26,730 --> 00:01:30,240 you'll see sha256 Hash, same as we 39 00:01:30,240 --> 00:01:32,580 have seen for hello-world image, but 40 00:01:32,580 --> 00:01:34,980 of course hash itself is different 41 00:01:34,980 --> 00:01:37,410 here from the hash for hello-world 42 00:01:37,440 --> 00:01:39,930 image. Also, you see finally the 43 00:01:39,960 --> 00:01:42,600 image was downloaded, it's status is 44 00:01:42,600 --> 00:01:45,660 downloaded; but afterwards after we 45 00:01:45,660 --> 00:01:47,640 have executed basically 'docker run 46 00:01:47,670 --> 00:01:50,160 ubuntu' command, we have returned to 47 00:01:50,160 --> 00:01:52,260 terminal, it means that actually 48 00:01:52,260 --> 00:01:54,390 nothing happens. And we are not 49 00:01:54,420 --> 00:01:57,180 able to do something inside of the 50 00:01:57,210 --> 00:02:00,360 ubuntu container. But it was 51 00:02:00,420 --> 00:02:02,640 immediately terminated afterwards. 52 00:02:02,910 --> 00:02:05,760 Why? Because there was no command 53 00:02:05,790 --> 00:02:07,860 that was executed inside of this 54 00:02:07,890 --> 00:02:10,258 ubuntu container. And if there are 55 00:02:10,288 --> 00:02:12,750 no processes running inside of the 56 00:02:12,750 --> 00:02:15,120 container, Docker automatically 57 00:02:15,120 --> 00:02:17,730 terminates the container. And if I 58 00:02:17,790 --> 00:02:20,370 enter 'docker ps' now, you will see 59 00:02:20,370 --> 00:02:22,440 that there are no containers 60 00:02:22,470 --> 00:02:25,710 running. But I am able to observe 61 00:02:25,740 --> 00:02:28,170 history of the containers that were 62 00:02:28,230 --> 00:02:30,180 exited. For that you could use 63 00:02:30,180 --> 00:02:33,100 command 'docker ps' with option '-a' 64 00:02:33,100 --> 00:02:35,700 like so. And now I will see that 65 00:02:35,730 --> 00:02:38,790 there was container that was based 66 00:02:38,790 --> 00:02:41,580 on ubuntu image, and there was 67 00:02:41,580 --> 00:02:43,860 command, this one that was executed 68 00:02:43,890 --> 00:02:45,390 automatically, here is this 69 00:02:45,390 --> 00:02:48,330 command. But we have not performed 70 00:02:48,330 --> 00:02:50,220 anything inside of the bash, inside 71 00:02:50,220 --> 00:02:52,080 of the container. That's why 72 00:02:52,080 --> 00:02:54,210 container has decided that bash 73 00:02:54,240 --> 00:02:56,340 should exit, and it was exited, 74 00:02:56,370 --> 00:02:58,650 process was terminated. And 75 00:02:58,680 --> 00:03:00,960 afterwards, Docker has exited 76 00:03:00,960 --> 00:03:03,150 container as well. That's why here 77 00:03:03,150 --> 00:03:04,680 you see that the status of this 78 00:03:04,680 --> 00:03:06,960 container is 'Exited About a minute 79 00:03:06,960 --> 00:03:09,720 ago'. Also you see information about 80 00:03:09,750 --> 00:03:11,190 previous containers that we have 81 00:03:11,190 --> 00:03:12,720 created in the previous lecture. 82 00:03:12,930 --> 00:03:15,420 And we have used there hello-world 83 00:03:15,450 --> 00:03:17,610 images, here, and here. We have 84 00:03:17,640 --> 00:03:19,140 created basically two different 85 00:03:19,140 --> 00:03:20,910 containers, and you see that they 86 00:03:20,940 --> 00:03:22,890 were exited about an hour ago. 87 00:03:23,430 --> 00:03:25,710 Okay, that is the status of this 88 00:03:25,710 --> 00:03:27,780 container that we have tried to 89 00:03:27,780 --> 00:03:30,840 create using 'docker run' command. 90 00:03:31,650 --> 00:03:34,290 Also, if I will list now local 91 00:03:34,320 --> 00:03:37,260 images with command 'docker images', 92 00:03:37,530 --> 00:03:39,540 I should see here ubuntu image 93 00:03:39,570 --> 00:03:42,000 on the list. That means that if 94 00:03:42,000 --> 00:03:43,800 I'll try to create one more 95 00:03:43,800 --> 00:03:46,500 container using Uubuntu image, it 96 00:03:46,500 --> 00:03:48,450 will be created using the same 97 00:03:48,660 --> 00:03:50,880 image as you see here, there was no 98 00:03:50,880 --> 00:03:53,370 need to pull the same image from 99 00:03:53,400 --> 00:03:55,680 Docker Hub. Let's try that again. 100 00:03:55,860 --> 00:03:57,300 And let's try it with the same 101 00:03:57,300 --> 00:03:58,710 command as we have used before, 102 00:03:59,100 --> 00:04:04,380 'docker run ubuntu', and we see actually 103 00:04:04,380 --> 00:04:06,720 nothing. But again, under the hood, 104 00:04:06,780 --> 00:04:09,360 Docker has created a new container 105 00:04:09,480 --> 00:04:11,970 based on this image. There was no 106 00:04:11,970 --> 00:04:13,710 need again to pull it from Docker 107 00:04:13,740 --> 00:04:15,420 Hub, because we already have it 108 00:04:15,420 --> 00:04:17,610 here on the list. But afterwards 109 00:04:17,610 --> 00:04:19,529 container was again automatically 110 00:04:19,529 --> 00:04:21,660 terminated. Let's have a look at 111 00:04:21,660 --> 00:04:24,149 history of containers. 'docker ps 112 00:04:24,209 --> 00:04:26,040 -a', actually there is 113 00:04:26,070 --> 00:04:27,839 alternative command to 'docker ps', 114 00:04:27,839 --> 00:04:29,280 and this command is 'docker 115 00:04:29,280 --> 00:04:32,130 container ls', and if l type here 116 00:04:32,160 --> 00:04:36,150 'docker container ls -a', you'll 117 00:04:36,150 --> 00:04:38,340 see actually same result as with 118 00:04:38,370 --> 00:04:41,910 'docker ps -a', it brings us 119 00:04:41,940 --> 00:04:44,220 history of all containers that were 120 00:04:44,220 --> 00:04:46,290 created before. And again you see 121 00:04:46,290 --> 00:04:48,600 here one more container that was 122 00:04:48,600 --> 00:04:51,090 created using ubuntu image, and this 123 00:04:51,090 --> 00:04:53,220 container was exited a minute ago. 124 00:04:53,640 --> 00:04:55,050 Here below you see a second 125 00:04:55,050 --> 00:04:56,580 container with the same image 126 00:04:56,580 --> 00:04:59,070 ubuntu, but this one was exited 4 127 00:04:59,100 --> 00:05:01,830 minutes ago. It means that each 128 00:05:01,830 --> 00:05:03,600 time when you execute the command 129 00:05:03,630 --> 00:05:05,700 'docker run' and some image, 130 00:05:05,820 --> 00:05:07,680 Docker creates a new container 131 00:05:07,710 --> 00:05:10,980 based on specific image. But now 132 00:05:10,980 --> 00:05:13,170 you may ask me a question, how we 133 00:05:13,170 --> 00:05:15,630 are actually able to log in into 134 00:05:15,630 --> 00:05:16,980 that container, ubuntu 135 00:05:16,980 --> 00:05:19,530 container, and execute some commands 136 00:05:19,560 --> 00:05:21,240 inside of the Ubuntu operating 137 00:05:21,240 --> 00:05:23,880 system. Answer is pretty simple. 138 00:05:24,030 --> 00:05:27,450 Let me show you. 'docker run - 139 00:05:27,450 --> 00:05:30,660 it ubuntu'; let's press Enter and 140 00:05:30,660 --> 00:05:32,850 see what will happen. And now you 141 00:05:32,850 --> 00:05:35,130 see that I have basically entered 142 00:05:35,310 --> 00:05:37,680 bash shell inside of the Ubuntu 143 00:05:37,710 --> 00:05:40,230 container, and I have logged in 144 00:05:40,260 --> 00:05:43,140 automatically as a 'root' user, here 145 00:05:43,170 --> 00:05:45,240 you see that. And here is actually 146 00:05:45,240 --> 00:05:48,120 ID of this container that was just 147 00:05:48,150 --> 00:05:51,240 created. And now I am still inside 148 00:05:51,240 --> 00:05:53,760 of this container, and container is 149 00:05:53,760 --> 00:05:56,700 still running. Let me show you that it 150 00:05:56,700 --> 00:05:58,380 is still running. Let me open up a 151 00:05:58,410 --> 00:06:00,750 new tab here in terminal, and let's 152 00:06:00,780 --> 00:06:03,360 enter 'docker ps' command. Here you 153 00:06:03,360 --> 00:06:05,400 see image that was used, this ubuntu, 154 00:06:05,610 --> 00:06:08,100 and also you see here CONTAINER ID, 155 00:06:08,310 --> 00:06:10,860 and this ID is the same as you see 156 00:06:10,890 --> 00:06:13,650 here in this bash shell inside of 157 00:06:13,650 --> 00:06:16,350 the ubuntu container. And now 158 00:06:16,350 --> 00:06:18,780 actually, we are able to perform 159 00:06:18,780 --> 00:06:20,100 some operations inside of this 160 00:06:20,100 --> 00:06:22,290 container. For example, let's use 161 00:06:22,320 --> 00:06:24,930 ls command and list files inside of 162 00:06:24,930 --> 00:06:26,970 the ubuntu container. And here you 163 00:06:26,970 --> 00:06:28,860 see some set of folders. And for 164 00:06:28,860 --> 00:06:30,960 example, you are able to list the 165 00:06:31,200 --> 00:06:33,270 files inside of the 'bin' folder. 166 00:06:33,300 --> 00:06:36,000 Let's do that 'ls bin', and you'll see 167 00:06:36,060 --> 00:06:38,610 some set of executables that you 168 00:06:38,610 --> 00:06:40,260 are able to use inside of the 169 00:06:40,290 --> 00:06:42,360 ubuntu container. Again, please 170 00:06:42,360 --> 00:06:45,090 notice that this set of files and 171 00:06:45,090 --> 00:06:47,700 folders is completely isolated 172 00:06:47,700 --> 00:06:49,650 inside of this ubuntu container. It 173 00:06:49,650 --> 00:06:52,410 is not a set of files on my macOS 174 00:06:52,410 --> 00:06:54,510 computer where I am running Docker 175 00:06:54,510 --> 00:06:56,100 right now. Actually, let me show 176 00:06:56,100 --> 00:06:57,780 you that to prove that. Let me 177 00:06:57,780 --> 00:06:59,670 open up one more tab, and here 178 00:06:59,700 --> 00:07:02,460 let me 'ls', and you'll see actually a 179 00:07:02,460 --> 00:07:05,130 list of folders on this macOS 180 00:07:05,130 --> 00:07:08,070 computer. And also I'm able to list 181 00:07:08,070 --> 00:07:10,260 the actually files in '/bin' 182 00:07:10,260 --> 00:07:12,120 folder, and you'll see a set of 183 00:07:12,120 --> 00:07:14,820 executables on my macOS computer. 184 00:07:15,120 --> 00:07:17,190 And this set of executables is of 185 00:07:17,190 --> 00:07:19,530 course different from this set of 186 00:07:19,530 --> 00:07:21,840 executable files. That's how you're 187 00:07:21,840 --> 00:07:23,970 able to list the files inside of 188 00:07:23,970 --> 00:07:26,490 the container. And again, container 189 00:07:26,520 --> 00:07:29,160 is still running. You could verify 190 00:07:29,160 --> 00:07:32,070 that here, 'docker ps', and you see 191 00:07:32,100 --> 00:07:33,960 that there is container with ubuntu 192 00:07:33,960 --> 00:07:35,790 image that is up and running and it 193 00:07:35,790 --> 00:07:38,640 is 'Up 2 minutes'. And also you see 194 00:07:38,640 --> 00:07:41,640 here which command was executed '/bin 195 00:07:41,670 --> 00:07:45,390 /bash', it is bash shell, and we are 196 00:07:45,390 --> 00:07:47,190 actually located now in this bash 197 00:07:47,190 --> 00:07:49,620 shell. Okay, please notice that 198 00:07:49,650 --> 00:07:51,870 this container runs now full 199 00:07:51,870 --> 00:07:54,390 featured Ubuntu operating system 200 00:07:54,600 --> 00:07:56,070 and you could verify version of 201 00:07:56,070 --> 00:07:57,990 this operating system using 'cat 202 00:07:58,410 --> 00:08:01,710 /etc/os-release'. 203 00:08:01,740 --> 00:08:05,000 You see here version Ubuntu 18.04.4 204 00:08:05,000 --> 00:08:06,840 Long Term Support release. 205 00:08:07,260 --> 00:08:08,820 Also we could try something else. 206 00:08:08,850 --> 00:08:10,740 Let's try for example 'echo' command. 207 00:08:10,860 --> 00:08:12,780 Let me clear terminal; and type 208 00:08:12,810 --> 00:08:16,440 echo "Hello from Ubuntu 209 00:08:16,950 --> 00:08:20,010 container", Enter, and you'll see 210 00:08:20,010 --> 00:08:22,050 "Hello from Ubuntu container", here in 211 00:08:22,050 --> 00:08:24,420 this shell. Please notice that we 212 00:08:24,420 --> 00:08:26,250 are able to use this command 213 00:08:26,400 --> 00:08:28,530 because there is such executable 214 00:08:28,530 --> 00:08:30,270 inside of the bin folder. Let me 215 00:08:30,270 --> 00:08:32,100 list contents of the bin folder once 216 00:08:32,100 --> 00:08:34,169 again. And you'll see here 'echo' on 217 00:08:34,169 --> 00:08:36,179 the list. Let's try something else. 218 00:08:36,200 --> 00:08:39,100 Let's clear terminal, and type 'hostname' 219 00:08:39,100 --> 00:08:40,700 command; and you'll see here 220 00:08:40,710 --> 00:08:43,080 hostname of this container. It 221 00:08:43,080 --> 00:08:45,299 actually matches with this ID here 222 00:08:45,299 --> 00:08:47,700 on the list. Also, we're able to verify 223 00:08:47,730 --> 00:08:49,980 which IP address was assigned to 224 00:08:49,980 --> 00:08:52,039 this container using command 'hostname' 225 00:08:52,039 --> 00:08:54,000 -i', like so, and you'll see 226 00:08:54,000 --> 00:08:58,410 IP address 172.17.0.2 here in this 227 00:08:58,440 --> 00:09:00,750 output. Great. That's how you're 228 00:09:00,750 --> 00:09:02,400 able to perform some commands 229 00:09:02,430 --> 00:09:04,350 inside of the ubuntu container. 230 00:09:04,800 --> 00:09:07,230 Let's now type 'exit', and let's exit 231 00:09:07,230 --> 00:09:11,220 from this bash shell. 'exit', and we 232 00:09:11,220 --> 00:09:13,110 can return back to our terminal. 233 00:09:13,530 --> 00:09:15,930 Let's now list the containers that 234 00:09:15,960 --> 00:09:19,980 are currently running, 'docker ps', and 235 00:09:19,980 --> 00:09:22,320 you'll see empty output. Basically 236 00:09:22,320 --> 00:09:23,670 you're able to use alternative 237 00:09:23,670 --> 00:09:25,680 command to 'docker ps', 'docker 238 00:09:25,740 --> 00:09:28,860 container ls'; and you'll see same 239 00:09:28,890 --> 00:09:31,170 result. There are no containers 240 00:09:31,200 --> 00:09:33,900 currently running. But if I enter 241 00:09:33,930 --> 00:09:36,600 'docker ps -a', you'll see that 242 00:09:36,630 --> 00:09:39,990 our ubuntu container was exited 34 243 00:09:40,020 --> 00:09:43,350 seconds ago. Why it was exited? 244 00:09:43,680 --> 00:09:45,630 Answer is pretty simple. We have 245 00:09:45,660 --> 00:09:48,150 exited from bash shell inside of 246 00:09:48,150 --> 00:09:50,760 the container, and that terminated 247 00:09:50,790 --> 00:09:52,260 bash process inside of the 248 00:09:52,260 --> 00:09:54,570 container. And when there are no 249 00:09:54,570 --> 00:09:56,160 processes running inside of the 250 00:09:56,160 --> 00:09:58,860 container, Docker simply terminates 251 00:09:58,890 --> 00:10:01,440 such container. That's what actually 252 00:10:01,440 --> 00:10:03,090 happened here in this example. 253 00:10:03,990 --> 00:10:05,550 Great. Let's also clear 254 00:10:05,550 --> 00:10:07,500 terminal and let's have a look at 255 00:10:07,530 --> 00:10:10,284 the size of the image that was downloaded 256 00:10:10,284 --> 00:10:11,610 for ubuntu containers, 257 00:10:11,850 --> 00:10:15,180 'docker images', like so. And here 258 00:10:15,180 --> 00:10:17,730 you'll see size equal to 64. 259 00:10:17,790 --> 00:10:20,280 megabyte. It is of course much more 260 00:10:20,310 --> 00:10:22,200 larger than the size of the hello- 261 00:10:22,200 --> 00:10:24,360 world container that was simply 262 00:10:24,450 --> 00:10:26,520 less than two kilobytes in size. 263 00:10:26,760 --> 00:10:29,610 But this size is relatively small 264 00:10:29,610 --> 00:10:32,370 in comparison to let's say, Docker 265 00:10:32,370 --> 00:10:34,560 installation itself that was around 266 00:10:34,590 --> 00:10:36,840 two gigabytes for macOS or Windows 267 00:10:36,840 --> 00:10:39,870 computer. But this size is still 268 00:10:39,900 --> 00:10:43,140 large in the Docker world, because 269 00:10:43,140 --> 00:10:45,360 we have used here full featured 270 00:10:45,420 --> 00:10:47,820 Ubuntu operating system. And in the 271 00:10:47,820 --> 00:10:49,470 next example, I would like to 272 00:10:49,470 --> 00:10:51,420 demonstrate you how you're able to 273 00:10:51,420 --> 00:10:54,150 create the Linux container using 274 00:10:54,180 --> 00:10:56,730 smallest image possible. Let's try 275 00:10:56,730 --> 00:10:57,967 that next. Bye-Bye. 276 00:10:57,967 --> 00:11:00,032 [no audio]