1 00:00:00,000 --> 00:00:04,300 [Intro Music] 2 00:00:04,319 --> 00:00:06,359 Before going on with Python, let me 3 00:00:06,359 --> 00:00:08,249 demonstrate you how you're able to 4 00:00:08,429 --> 00:00:10,409 remove containers and prune 5 00:00:10,409 --> 00:00:12,059 containers. Because at the moment, 6 00:00:12,089 --> 00:00:13,139 there are actually a lot of 7 00:00:13,139 --> 00:00:14,729 containers that we have created 8 00:00:14,729 --> 00:00:16,588 before, but now they are stopped. 9 00:00:16,889 --> 00:00:18,599 Also, you are actually able to 10 00:00:18,599 --> 00:00:21,359 start over any stopped container. 11 00:00:21,689 --> 00:00:23,039 Actually, at the moment, there are 12 00:00:23,039 --> 00:00:25,319 still two nginx containers running. 13 00:00:25,529 --> 00:00:27,299 Let me stop them. And afterwards, 14 00:00:27,299 --> 00:00:29,099 I'll demonstrate you how to start 15 00:00:29,129 --> 00:00:31,559 over stopped container, remove stopped 16 00:00:31,559 --> 00:00:33,448 container, and prune all stopped 17 00:00:33,448 --> 00:00:35,639 containers. Let's do that. Let me 18 00:00:35,639 --> 00:00:37,439 stop this container, and let me 19 00:00:37,439 --> 00:00:40,499 stop this one as well. And I don't 20 00:00:40,499 --> 00:00:42,809 need the two windows anymore. Let 21 00:00:42,809 --> 00:00:45,299 me use just one like this. And I 22 00:00:45,299 --> 00:00:47,879 could go out from the nginx1 23 00:00:47,879 --> 00:00:49,289 folder. Let's 'cd' to 24 00:00:49,289 --> 00:00:51,239 'containers', and let's clear 25 00:00:51,269 --> 00:00:53,069 terminal, and let's list 26 00:00:53,069 --> 00:00:54,329 containers that are currently 27 00:00:54,359 --> 00:00:56,639 running. And as you have guessed, 28 00:00:56,939 --> 00:00:58,829 probably there are no containers 29 00:00:58,829 --> 00:01:00,719 running at the moment. But if I 30 00:01:00,719 --> 00:01:02,969 enter 'docker ps -a', you 31 00:01:02,969 --> 00:01:05,099 should see all previous containers 32 00:01:05,129 --> 00:01:06,929 starting from the very first one 33 00:01:07,019 --> 00:01:09,179 where we have used the hello-world 34 00:01:09,209 --> 00:01:11,609 image. Also, if you scroll to the 35 00:01:11,609 --> 00:01:13,079 beginning of this output, you 36 00:01:13,079 --> 00:01:15,449 should see nginx containers that 37 00:01:15,449 --> 00:01:18,539 were exited just several minutes 38 00:01:18,569 --> 00:01:20,819 ago. Here are those containers in 39 00:01:20,819 --> 00:01:22,889 my case. And you see that this 40 00:01:22,889 --> 00:01:25,139 container was exited 30 seconds ago 41 00:01:25,139 --> 00:01:28,589 and this one 48 seconds ago. And those 42 00:01:28,589 --> 00:01:31,169 containers were created 24 hours 43 00:01:31,169 --> 00:01:33,449 ago. Great. Let me now demonstrate 44 00:01:33,449 --> 00:01:35,549 you how we are able to start over 45 00:01:35,579 --> 00:01:37,439 stopped containers or exited 46 00:01:37,439 --> 00:01:40,139 containers. Let me for example, try 47 00:01:40,169 --> 00:01:42,479 to run over this container with 48 00:01:42,479 --> 00:01:45,719 name 'nginx2'. Let's do so. Clear 49 00:01:45,719 --> 00:01:47,369 terminal. And for that you could 50 00:01:47,369 --> 00:01:50,429 use Command 'docker start', and 51 00:01:50,459 --> 00:01:53,189 ID or name of the container. We 52 00:01:53,189 --> 00:01:55,169 have created named containers, that's 53 00:01:55,169 --> 00:01:56,909 why I'm able to use those names 54 00:01:56,909 --> 00:01:59,309 here, nginx1 or nginx2. 55 00:01:59,609 --> 00:02:02,489 Let's use 'nginx2' name here. 56 00:02:03,929 --> 00:02:05,909 Container was started, and I could 57 00:02:05,909 --> 00:02:07,619 verify that using 'docker ps' 58 00:02:07,619 --> 00:02:09,389 command. And you'll see that now 59 00:02:09,538 --> 00:02:11,729 this container is again up and 60 00:02:11,729 --> 00:02:14,339 running. Let's verify whether I 61 00:02:14,339 --> 00:02:15,839 will be able to connect to this 62 00:02:15,869 --> 00:02:18,029 nginx server or not using this 63 00:02:18,149 --> 00:02:20,159 external port. Let's go to web 64 00:02:20,159 --> 00:02:22,289 browser, actually I have those two 65 00:02:22,289 --> 00:02:24,419 tabs open, let me close this one, and 66 00:02:24,419 --> 00:02:26,459 let's refresh this page, and you 67 00:02:26,459 --> 00:02:28,709 see that it actually works. And it 68 00:02:28,709 --> 00:02:30,809 works even if I am located not 69 00:02:30,809 --> 00:02:32,939 inside of the nginx2 folder. 70 00:02:33,359 --> 00:02:35,009 You see that now I am in 'containers' 71 00:02:35,009 --> 00:02:36,959 folder. In this case it does not 72 00:02:36,959 --> 00:02:39,719 matter because this container is 73 00:02:39,719 --> 00:02:42,059 actually configuration has mapping 74 00:02:42,269 --> 00:02:44,039 of specific folder, 'nginx2' 75 00:02:44,039 --> 00:02:46,319 folder to internal folder inside of 76 00:02:46,319 --> 00:02:47,939 the container. That's why there is 77 00:02:47,939 --> 00:02:50,429 no need to move into nginx2 78 00:02:50,429 --> 00:02:52,799 folder, and start container there. 79 00:02:53,189 --> 00:02:54,749 Let me actually verify whether I 80 00:02:54,749 --> 00:02:57,059 will be able to modify files. Let's 81 00:02:57,059 --> 00:02:59,759 go to nginx2 folder, index.html, 82 00:02:59,939 --> 00:03:03,089 and add one more exclamation mark 83 00:03:03,089 --> 00:03:05,729 here, go to web browser, refresh page, 84 00:03:05,849 --> 00:03:07,919 and yes it works. That's how 85 00:03:07,919 --> 00:03:10,319 you're able to start over any 86 00:03:10,349 --> 00:03:12,899 stopped container. As a challenge 87 00:03:12,900 --> 00:03:15,300 you could start for example nginx1 88 00:03:15,300 --> 00:03:17,100 container, and verify whether it 89 00:03:17,129 --> 00:03:19,019 will still work or not. Also as a 90 00:03:19,019 --> 00:03:20,639 challenge you are able to try to 91 00:03:20,639 --> 00:03:22,859 start any other of the stopped 92 00:03:22,859 --> 00:03:25,679 containers. Next, let me now first 93 00:03:25,679 --> 00:03:27,569 stop this container, and I am 94 00:03:27,569 --> 00:03:30,779 able to use Command 'docker stop', and 95 00:03:30,779 --> 00:03:32,819 use either ID of the container or 96 00:03:32,819 --> 00:03:34,919 its name. Let's use first few 97 00:03:34,919 --> 00:03:37,769 characters of the ID, '6e', and 98 00:03:37,769 --> 00:03:39,449 container was stopped. Let's verify 99 00:03:39,449 --> 00:03:41,969 that. 'docker ps', and yes there are no 100 00:03:42,029 --> 00:03:44,459 containers currently running. But if I 101 00:03:44,459 --> 00:03:46,409 list the containers in the history, 102 00:03:46,619 --> 00:03:49,319 I'll still see nginx2 container, 103 00:03:49,349 --> 00:03:52,379 here it is with nginx2 name. Great. 104 00:03:52,589 --> 00:03:53,879 Let me now demonstrate you how we 105 00:03:53,879 --> 00:03:55,769 are able to remove a specific 106 00:03:55,769 --> 00:03:57,839 container from this list. For that 107 00:03:57,839 --> 00:04:00,209 you could use the command 'docker rm', 108 00:04:00,389 --> 00:04:03,419 or 'docker container rm'. Let's first 109 00:04:03,419 --> 00:04:06,089 try 'docker rm'. Let's clear 110 00:04:06,089 --> 00:04:08,999 terminal, 'docker rm', and here type 111 00:04:09,029 --> 00:04:11,669 name or ID of the container, let's 112 00:04:11,669 --> 00:04:15,269 type nginx2. Container was 113 00:04:15,269 --> 00:04:16,769 removed. And now if I list 114 00:04:16,769 --> 00:04:20,800 containers, 'docker ps -a', scroll up, 115 00:04:20,800 --> 00:04:22,800 [no audio] 116 00:04:22,800 --> 00:04:25,300 I will see that there is no nginx2 117 00:04:25,300 --> 00:04:27,800 container anymore. And basically 118 00:04:27,870 --> 00:04:29,520 we have performed this action 119 00:04:29,760 --> 00:04:30,990 before in one of the previous 120 00:04:30,990 --> 00:04:32,850 lectures when we have tried to 121 00:04:32,850 --> 00:04:34,470 create a container with the same 122 00:04:34,470 --> 00:04:36,450 name; and Docker does not allow you 123 00:04:36,450 --> 00:04:38,250 to do so. It is not possible to 124 00:04:38,250 --> 00:04:40,200 create containers with the same 125 00:04:40,230 --> 00:04:42,330 name even if a container was 126 00:04:42,330 --> 00:04:44,670 stopped. Great. Let me now try to 127 00:04:44,670 --> 00:04:46,650 stop any other container, actually, 128 00:04:46,650 --> 00:04:48,660 sorry, remove container, and let me 129 00:04:48,690 --> 00:04:50,730 do so with a container with this 130 00:04:50,730 --> 00:04:52,860 name. Let me copy this name, it was 131 00:04:52,890 --> 00:04:55,380 ubuntu container, and let's use the 132 00:04:55,380 --> 00:04:58,170 'docker rm' command again, and paste 133 00:04:58,170 --> 00:04:59,970 here name of that container, 134 00:04:59,970 --> 00:05:03,000 and container was removed. Let's remove 135 00:05:03,060 --> 00:05:05,370 for example also this one. Let me 136 00:05:05,460 --> 00:05:07,560 copy this name. In your case, you 137 00:05:07,560 --> 00:05:09,330 could choose any other names of 138 00:05:09,330 --> 00:05:10,860 your containers because those names 139 00:05:10,860 --> 00:05:13,140 were randomly generated, that's why 140 00:05:13,170 --> 00:05:14,400 in your case names will be 141 00:05:14,400 --> 00:05:17,010 different. 'docker rm', paste this name, 142 00:05:17,040 --> 00:05:18,930 and this container was removed as 143 00:05:18,930 --> 00:05:22,050 well. If you want to remove all 144 00:05:22,050 --> 00:05:24,120 stopped containers just in a one 145 00:05:24,120 --> 00:05:26,010 shift, you are able to use the 146 00:05:26,010 --> 00:05:27,900 command 'docker prune'. Let me 147 00:05:27,900 --> 00:05:30,060 actually use 'docker --help' 148 00:05:30,060 --> 00:05:31,950 command and show you a description of 149 00:05:31,950 --> 00:05:33,360 that command. And we need to 150 00:05:33,360 --> 00:05:35,220 basically use Management Command, 151 00:05:35,220 --> 00:05:36,930 Container Management Command. Let 152 00:05:36,930 --> 00:05:38,910 me scroll up, and this command 153 00:05:38,910 --> 00:05:40,830 should be used. So let me type here 154 00:05:40,830 --> 00:05:43,230 'docker container --help', 155 00:05:43,230 --> 00:05:45,180 instead of simply 'docker --help'; and 156 00:05:45,180 --> 00:05:47,370 here you'll find a list of commands 157 00:05:47,550 --> 00:05:49,050 that you are able to use with 158 00:05:49,110 --> 00:05:51,390 Container Management Command. And 159 00:05:51,390 --> 00:05:53,130 here is 'prune' command that will 160 00:05:53,130 --> 00:05:56,100 remove all stopped containers. And 161 00:05:56,100 --> 00:05:57,990 now's a good time to remove all 162 00:05:57,990 --> 00:05:59,970 stopped containers just in one shift 163 00:05:59,970 --> 00:06:02,790 using one command 'docker container 164 00:06:02,820 --> 00:06:04,500 prune'. Let's do that. Let's clear 165 00:06:04,500 --> 00:06:07,110 terminal, 'docker container 166 00:06:07,320 --> 00:06:10,710 prune'. 'This will remove all stopped 167 00:06:10,710 --> 00:06:12,120 containers. Are you sure you want 168 00:06:12,120 --> 00:06:14,160 to continue?' And if you are sure, 169 00:06:14,190 --> 00:06:17,940 just type 'Y', and press Enter; and 170 00:06:17,970 --> 00:06:20,490 all containers were removed. And 171 00:06:20,490 --> 00:06:23,670 the total reclaimed space is 766 172 00:06:23,670 --> 00:06:25,500 bytes. It is less than one 173 00:06:25,500 --> 00:06:27,150 kilobyte. And that is actually the 174 00:06:27,150 --> 00:06:28,860 beauty of Docker, all those 175 00:06:28,860 --> 00:06:30,870 containers that were run before and 176 00:06:30,870 --> 00:06:33,390 that were stopped afterwards used 177 00:06:33,390 --> 00:06:35,550 less than one kilobyte of disk 178 00:06:35,550 --> 00:06:38,670 size. All right. That's how we were 179 00:06:38,670 --> 00:06:40,980 able to remove all stopped containers. 180 00:06:41,010 --> 00:06:42,390 And you could verify that using 181 00:06:42,450 --> 00:06:45,390 'docker ps -a', and you'll see no 182 00:06:45,390 --> 00:06:46,980 containers here in the history. 183 00:06:47,520 --> 00:06:48,600 Actually I have forgotten to 184 00:06:48,600 --> 00:06:50,220 demonstrate you how you are able 185 00:06:50,250 --> 00:06:52,650 to remove multiple containers using 186 00:06:52,680 --> 00:06:54,720 multiple IDs. Let me quickly 187 00:06:54,720 --> 00:06:56,190 demonstrate you that. Let me clear 188 00:06:56,190 --> 00:06:58,620 terminal and quickly run two 189 00:06:58,620 --> 00:07:01,600 containers, for example, 'docker run alpine' 190 00:07:01,600 --> 00:07:03,800 [no audio] 191 00:07:03,800 --> 00:07:05,600 and 'docker run alpine' once 192 00:07:05,610 --> 00:07:08,850 again. And now I should have two 193 00:07:08,880 --> 00:07:10,830 stopped containers. And yes, that 194 00:07:10,830 --> 00:07:13,020 is the case. And now let me use 195 00:07:13,050 --> 00:07:15,840 'docker container rm' command, 196 00:07:15,960 --> 00:07:18,360 actually it is equivalent to 'docker rm' 197 00:07:18,360 --> 00:07:20,700 command, and here I could type 198 00:07:20,700 --> 00:07:23,430 multiple names or multiple IDs of 199 00:07:23,430 --> 00:07:25,350 containers that I want to remove. 200 00:07:25,770 --> 00:07:29,100 Let me type here '05' like so, and 201 00:07:29,160 --> 00:07:32,250 after space '78', starting 202 00:07:32,250 --> 00:07:34,560 characters of those IDs of those 203 00:07:34,560 --> 00:07:36,120 two containers, this one and this 204 00:07:36,120 --> 00:07:38,970 one. Let's press Enter. And both 205 00:07:38,970 --> 00:07:41,760 containers were removed. 'docker ps 206 00:07:41,790 --> 00:07:44,610 -a', and I see no containers on 207 00:07:44,610 --> 00:07:46,590 the list. That's how you're able to 208 00:07:46,590 --> 00:07:48,630 use either 'rm' command or 'prune' 209 00:07:48,630 --> 00:07:50,880 command. And if you don't need 210 00:07:50,880 --> 00:07:52,650 containers anymore, from time to 211 00:07:52,650 --> 00:07:54,510 time run those commands in order to 212 00:07:54,510 --> 00:07:56,250 clean space and in order to free 213 00:07:56,280 --> 00:07:58,380 namespaces. That's all for this 214 00:07:58,380 --> 00:08:00,330 lecture, and next let's move on to 215 00:08:00,360 --> 00:08:02,340 python image, and create the 216 00:08:02,340 --> 00:08:04,170 container based on python image. 217 00:08:04,200 --> 00:08:05,610 Let's do that next. Bye-Bye. 218 00:08:05,610 --> 00:08:08,192 [no audio]