1 00:00:00,770 --> 00:00:05,700 In the last section we started investigating the lifecycle of a container by using the docker create 2 00:00:05,790 --> 00:00:07,700 and docker start commands. 3 00:00:07,710 --> 00:00:11,820 We're not going to start to investigate the status of some those containers that we've already started 4 00:00:11,880 --> 00:00:15,660 up on our machine but have closed down for some particular reason. 5 00:00:15,660 --> 00:00:19,540 So we can print those aloud with Docker P.S. dash dash all. 6 00:00:19,560 --> 00:00:25,520 You'll notice that I have just one container listed as exited now whereas before I had like 30. 7 00:00:25,560 --> 00:00:29,580 The reason for that is that I ran a command between the last video and this one to kind of pass down 8 00:00:29,580 --> 00:00:33,630 that list and of course I will show you that command in just a second as well. 9 00:00:33,660 --> 00:00:40,060 So at this point the only stopped or exit container that I have on my machine is this one right here. 10 00:00:40,110 --> 00:00:44,520 Let's try creating and running and then stopping one more container just to make sure that we're kind 11 00:00:44,520 --> 00:00:46,070 of on a level footing. 12 00:00:46,170 --> 00:00:50,760 So I'm going to execute Docker run Busy Box echo. 13 00:00:50,790 --> 00:00:58,550 Hi there if I then do Dr. P.S. dash dash all again and then zoom out so I can see this a little bit 14 00:00:58,550 --> 00:00:58,760 better. 15 00:00:58,760 --> 00:00:59,580 There we go. 16 00:00:59,600 --> 00:01:01,600 I'll see the idea that container. 17 00:01:01,670 --> 00:01:02,620 I'll see the echo. 18 00:01:02,630 --> 00:01:03,410 Hi there. 19 00:01:03,470 --> 00:01:09,200 And I can definitely verify that its status is definitely exited right now when the container is exited. 20 00:01:09,230 --> 00:01:11,390 We can still start it back up. 21 00:01:11,390 --> 00:01:16,490 So just because a container stop doesn't mean that it's like dead or cannot be used again we can very 22 00:01:16,490 --> 00:01:22,640 easily stop and then start containers again at some point in the future to start a container backup. 23 00:01:22,700 --> 00:01:31,480 We can take its I.D. and then execute Docker start and paste that idea at remember that if we use Docker 24 00:01:31,480 --> 00:01:33,460 start without the dash a flag. 25 00:01:33,460 --> 00:01:38,530 However we won't see any output from it and so it might be a little bit more useful to do Docker start 26 00:01:38,750 --> 00:01:43,430 dash and then the I.D. And when I do that you'll notice that it printed out. 27 00:01:43,430 --> 00:01:44,770 Hi there again. 28 00:01:44,770 --> 00:01:46,150 Which is kind of interesting. 29 00:01:46,150 --> 00:01:51,970 Let's take a look at a diagram to really understand this entire series of commands that we just issued. 30 00:01:52,030 --> 00:01:52,950 All right here we go. 31 00:01:53,910 --> 00:01:59,550 So we've got our busy box image and at some point time we definitely ran Docker create or Docker run 32 00:02:00,240 --> 00:02:05,370 that took our file system snapshot and essentially it got a reference to it inside the container. 33 00:02:05,520 --> 00:02:10,420 We then provided that override command of Echo. 34 00:02:10,470 --> 00:02:11,640 Hi there. 35 00:02:11,640 --> 00:02:15,210 So that was the primary running command inside the container. 36 00:02:15,540 --> 00:02:22,710 That command ran it then completed the container exited naturally and we then ran the docker start command 37 00:02:22,740 --> 00:02:24,080 a second time. 38 00:02:24,090 --> 00:02:32,080 What happened was the running process or this primary command was issued a second time inside the container. 39 00:02:32,250 --> 00:02:34,610 When you have a container that's already been created. 40 00:02:34,620 --> 00:02:39,440 We can not replace that default command as soon as you started up with the default command. 41 00:02:39,480 --> 00:02:40,170 That's it. 42 00:02:40,170 --> 00:02:42,440 The default command is then in place. 43 00:02:42,570 --> 00:02:50,460 So we cannot do something like say Docker starts Shea the I.D. and then try to replace the default command. 44 00:02:50,460 --> 00:02:53,690 I can't do something like Echo by there. 45 00:02:53,700 --> 00:02:56,840 So in theory this would be us trying to replace the default command again. 46 00:02:56,910 --> 00:02:57,690 Can't do that. 47 00:02:57,720 --> 00:03:01,630 And if we tried to run it go going to misinterpret the command that we just issued. 48 00:03:01,630 --> 00:03:07,410 It's thinking that we're trying to start up multiple containers at the same time so once we have started 49 00:03:07,410 --> 00:03:14,040 up a container and let it exit we can start it back up again which is going to reissue the default command 50 00:03:14,220 --> 00:03:17,940 that was used when the container was first created. 51 00:03:17,940 --> 00:03:18,170 All right. 52 00:03:18,170 --> 00:03:22,080 Now it might seem like going over all this life cycle stuff is kind of unimportant. 53 00:03:22,080 --> 00:03:27,300 It might seem like I'm going really far into the weeds with it but trust me having a solid understanding 54 00:03:27,330 --> 00:03:32,400 of the lifecycle of a container is gonna be so incredibly useful later on when it really comes down 55 00:03:32,400 --> 00:03:36,000 to figuring out how to troubleshoot these things and debug a running container. 56 00:03:36,390 --> 00:03:39,700 So I think we got a better idea of the lifecycle of a container. 57 00:03:39,700 --> 00:03:42,450 So let's take another quick break and continue in the next section.