1 00:00:01,040 --> 00:00:04,210 In all these commands we've been running with Docker create and start. 2 00:00:04,290 --> 00:00:07,250 There's kind of one oddity that I want to show you really quickly. 3 00:00:07,400 --> 00:00:12,950 Let's do a container creation and then a start and you'll see some kind of weird behavior. 4 00:00:13,010 --> 00:00:19,610 I'm gonna run a docker create Busy Box and then we're gonna setup that ping command again. 5 00:00:19,670 --> 00:00:24,530 So I'll say ping Google dot com that's going to create the container. 6 00:00:24,530 --> 00:00:30,620 I can then copy the idea right here and do Docker start and paste that idea and you'll notice that I 7 00:00:30,620 --> 00:00:33,000 did not put in the dash a. 8 00:00:33,080 --> 00:00:36,760 So I have not attached this container when I run that command. 9 00:00:36,800 --> 00:00:39,560 I see the idea of the container echoed back to me. 10 00:00:39,860 --> 00:00:45,050 And then I can do a docker logs and paste that idea in and I'll see that. 11 00:00:45,060 --> 00:00:47,640 Yep it is in fact running the pin command. 12 00:00:47,660 --> 00:00:53,090 And if I do the docker P.S. command I can see up that container is running and it's continuing to execute 13 00:00:53,090 --> 00:00:54,830 the pin command. 14 00:00:54,830 --> 00:00:56,970 Now there's just one kind of odd thing here. 15 00:00:57,080 --> 00:00:59,720 How do we actually stop this container. 16 00:00:59,720 --> 00:01:04,850 Remember the pin command is going to essentially go on forever and we have to actually send it a signal 17 00:01:04,880 --> 00:01:06,920 until it Hey ping command please stop. 18 00:01:06,920 --> 00:01:07,760 Like you're all done. 19 00:01:07,760 --> 00:01:10,610 No need to reach out to Google anymore. 20 00:01:10,610 --> 00:01:15,770 So we need to figure out a way to stop this running container in the past we've just been hitting control 21 00:01:15,770 --> 00:01:21,710 C on our keyboard or even allowed the container to automatically stop itself as was the case with the 22 00:01:21,710 --> 00:01:23,240 Echo command. 23 00:01:23,300 --> 00:01:31,220 So in order to stop a container that seems to be running amuck on its own we can issue either the docker 24 00:01:31,250 --> 00:01:34,730 stop command or the docker kill command. 25 00:01:34,880 --> 00:01:39,020 Both these are going to stop the running container but they look like they kind of do the same thing 26 00:01:39,020 --> 00:01:41,300 here so what's the difference between them. 27 00:01:41,300 --> 00:01:47,810 Well here's what happens behind the scenes when you issue a docker stop command a hardware signal is 28 00:01:47,810 --> 00:01:49,100 sent to the process. 29 00:01:49,110 --> 00:01:53,800 The primary process inside that container in the case of Docker stop. 30 00:01:53,810 --> 00:01:58,410 We send a sig term message which is short for terminate signal. 31 00:01:58,550 --> 00:02:03,200 It's a message that's going to be received by the process telling it essentially to shut down on its 32 00:02:03,200 --> 00:02:05,540 own time sic term is used. 33 00:02:05,540 --> 00:02:10,370 Any time that you want to stop a process inside of your container and shut the container down and you 34 00:02:10,370 --> 00:02:15,290 want to give that process inside there a little bit of time to shut itself down and do a little bit 35 00:02:15,290 --> 00:02:16,420 of cleanup. 36 00:02:16,490 --> 00:02:22,100 A lot of different programming languages have the ability for you to listen for these signals inside 37 00:02:22,100 --> 00:02:23,020 of your codebase. 38 00:02:23,090 --> 00:02:27,950 And as soon as you get that signal you could attempt to do a little bit of cleanup or maybe save some 39 00:02:27,950 --> 00:02:31,400 file or emit some message or something like that. 40 00:02:31,760 --> 00:02:40,340 On the other hand the docker kill command issue is a sig kill or kills signal to the primary running 41 00:02:40,340 --> 00:02:46,340 process inside the container so kill it essentially means you have to shut down right now and you do 42 00:02:46,340 --> 00:02:54,660 not get to do any additional work so ideally we always stop a container with the docker stop command 43 00:02:55,530 --> 00:02:59,670 in order to get the running process inside of it a little bit of time to shut itself down. 44 00:02:59,760 --> 00:03:04,890 Otherwise if it feels like the container has locked up and it's not responding to the docker stop command 45 00:03:05,130 --> 00:03:08,000 then we could issue Docker kill instead. 46 00:03:08,040 --> 00:03:13,470 Now one kind of little oddity or interesting thing about Docker stop when you issue Docker stop to a 47 00:03:13,470 --> 00:03:14,060 container. 48 00:03:14,100 --> 00:03:19,500 If the container does not automatically stop in 10 seconds then Docker is going to automatically fall 49 00:03:19,500 --> 00:03:22,240 back to issuing the docker kill command. 50 00:03:22,260 --> 00:03:27,850 So essentially at Docker stop is us being nice but it's only got 10 seconds to actually shut down. 51 00:03:27,850 --> 00:03:33,720 So let's now try using these commands on that kind of runaway container that we have right now. 52 00:03:33,720 --> 00:03:39,690 So again do Docker P.S. And I'll see that the pinging google doc command hears me pin Koogle dot com 53 00:03:39,840 --> 00:03:41,380 container is still running. 54 00:03:41,550 --> 00:03:49,190 So going to take the idea right there and I'll issue Docker stop and then I'll paste that idea in and 55 00:03:49,210 --> 00:03:51,690 then we're going to wait and notice how we're kind of waiting here. 56 00:03:51,700 --> 00:03:55,050 We're going to end up waiting just about ten seconds. 57 00:03:55,060 --> 00:04:03,340 We're waiting 10 seconds because it turns out that the ping command does not properly respond to a sig 58 00:04:03,400 --> 00:04:04,870 term message. 59 00:04:04,960 --> 00:04:09,130 The ping command doesn't really have the ability to say oh yeah I understand you want me to shut down 60 00:04:09,490 --> 00:04:12,880 the ping command is rather an analyst term for it. 61 00:04:12,880 --> 00:04:16,330 The ping command wants to do its own thing and just wants to run forever. 62 00:04:16,510 --> 00:04:21,730 And so after we waited those 10 seconds eventually the kill signal was sent to it telling it Hey ping 63 00:04:21,970 --> 00:04:22,590 you're done. 64 00:04:22,600 --> 00:04:23,250 Get out of here. 65 00:04:23,260 --> 00:04:24,270 Shut yourself down. 66 00:04:24,280 --> 00:04:27,060 And so that's why we had to wait a couple of seconds. 67 00:04:27,070 --> 00:04:28,900 Let's now take that container idea again. 68 00:04:28,900 --> 00:04:34,700 We're going to start the container back up and try killing it this time with using Docker kill Sol first. 69 00:04:34,720 --> 00:04:37,350 Start the container back up with Docker start. 70 00:04:37,360 --> 00:04:43,360 I'll pace the idea in and then I'll issue a docker kill and paste the idea again and this time you're 71 00:04:43,360 --> 00:04:46,000 going to see that's it instantly dead. 72 00:04:46,000 --> 00:04:47,070 No Grace Period. 73 00:04:47,080 --> 00:04:49,500 Just get out of here. 74 00:04:49,570 --> 00:04:49,810 All right. 75 00:04:49,840 --> 00:04:50,410 So that's it. 76 00:04:50,440 --> 00:04:54,790 That's the two commands that we're going to use for closing down containers that are running. 77 00:04:54,790 --> 00:05:00,160 Remember you can always get the idea the container ahead of time with Docker P.S. you can copy the I.D. 78 00:05:00,340 --> 00:05:02,890 and then run either dock or stop or Docker kill. 79 00:05:02,940 --> 00:05:07,570 And in general I do recommend use Docker stopped to give the processes inside there a chance to shut 80 00:05:07,570 --> 00:05:12,110 down and if they don't shut down nice nicely nicely as we saw with the pin command. 81 00:05:12,220 --> 00:05:16,810 Eventually Docker is going to fall back to issuing a kill on the container instead. 82 00:05:16,810 --> 00:05:17,050 All right. 83 00:05:17,050 --> 00:05:17,800 So that's pretty much it. 84 00:05:17,800 --> 00:05:20,710 Let's take another brief pause and continue in the next section.