1 00:00:00,680 --> 00:00:06,720 In the last section we ran the docker P.S. command and we saw one variation of it which was Docker. 2 00:00:06,720 --> 00:00:11,120 P.S. dash dash all when we ran dash dash all on here. 3 00:00:11,150 --> 00:00:16,040 We saw that we got a print up of all the containers we'd ever started up on our machine which was kind 4 00:00:16,040 --> 00:00:21,850 of interesting because it kind of begs the question When does a container like really get shut down. 5 00:00:21,860 --> 00:00:25,590 Why does it get shut down and what happens when it gets shut down. 6 00:00:25,640 --> 00:00:30,560 So starting this section I want to start to show you a little bit around the lifecycle of a container 7 00:00:30,800 --> 00:00:33,980 which is gonna give you a better idea of what's going on behind the scenes. 8 00:00:34,190 --> 00:00:39,440 Now before first investigating or just jumping to the end like figuring out what happens when a container 9 00:00:39,470 --> 00:00:44,150 gets shut down I want to kind of go all the way to the start and really figure out what happens when 10 00:00:44,150 --> 00:00:46,610 a container is first created. 11 00:00:46,610 --> 00:00:51,650 Now we've learned at this point that to start up a new container from an image we use the docker run 12 00:00:51,650 --> 00:00:52,180 command. 13 00:00:52,640 --> 00:00:57,620 But when we looked at this diagram remember we looked at this diagram like two or three sections ago. 14 00:00:57,620 --> 00:01:04,280 You'll notice that I put some very particular terminology here I said creating and running a container 15 00:01:05,030 --> 00:01:10,870 creating a container and actually starting it up are actually two separate processes. 16 00:01:11,510 --> 00:01:16,790 So there's actually two additional commands in addition to Docker run that we can use to start up a 17 00:01:16,790 --> 00:01:19,820 new container Docker run. 18 00:01:19,820 --> 00:01:26,870 Running that at your command line is identical to running two other commands together first Docker create 19 00:01:27,020 --> 00:01:33,170 and then Docker start as you might guess the docker create commands is used to create a container out 20 00:01:33,170 --> 00:01:36,980 of an image and then start is used to actually start an image. 21 00:01:37,370 --> 00:01:41,270 But at this point you might be a little bit curious of Hey what's the distinction between creating a 22 00:01:41,270 --> 00:01:43,880 container and actually starting a container. 23 00:01:43,880 --> 00:01:46,730 Let's look at a diagram that's gonna help you understand the differences between the two. 24 00:01:47,630 --> 00:01:52,340 So we've looked at a diagram like this several times before remember on our image over here we've got 25 00:01:52,340 --> 00:01:54,750 that kind of file system snapshot of sorts. 26 00:01:54,780 --> 00:02:01,810 And we've also got a start up command the process of creating a container is where we kind of take the 27 00:02:01,810 --> 00:02:06,680 file system in here and kind of prep it for use in this new Container. 28 00:02:07,060 --> 00:02:12,460 When we create the container we're just talking about kind of prepping or setting up this file system 29 00:02:12,460 --> 00:02:17,440 snapshot to be used to create the container to actually start the container. 30 00:02:17,440 --> 00:02:22,990 That's when we actually execute the start up command that might start up the process of like hello world 31 00:02:23,380 --> 00:02:28,870 or in the case of that busy box one that we use the echo Hi there or whatever process is supposed to 32 00:02:28,870 --> 00:02:31,000 be executed inside the container. 33 00:02:31,000 --> 00:02:37,170 So again creating container is about the file system starting it is about actually executing the start 34 00:02:37,170 --> 00:02:38,650 up command. 35 00:02:38,650 --> 00:02:42,700 So with that in mind let's try flipping over to our command line really quickly and we're gonna start 36 00:02:42,700 --> 00:02:49,500 to investigate the differences between creating container and starting and container over it my my command 37 00:02:49,500 --> 00:02:49,980 line. 38 00:02:49,980 --> 00:02:56,820 I'm going to first try running the docker create and start commands with the hello world image. 39 00:02:56,820 --> 00:03:05,190 So I will first do Docker creates Hello dash world when I run that command I get this long string of 40 00:03:05,190 --> 00:03:06,490 characters printed out. 41 00:03:06,630 --> 00:03:13,890 This is the I.D. of the container that was just created I can now actually execute the hello world command 42 00:03:13,920 --> 00:03:21,000 inside of this container by running Docker start and I'm going to add on a little argument here I'm 43 00:03:21,000 --> 00:03:26,430 going to say dash a we'll talk about what that isn't just a second and then I'm going to paste the I.D. 44 00:03:26,670 --> 00:03:31,650 that was just emitted right here I'm going to paste in that really long series of characters and then 45 00:03:31,650 --> 00:03:36,170 when I run this command we'll see that familiar welcome message appear. 46 00:03:36,330 --> 00:03:37,350 So what happened here. 47 00:03:37,350 --> 00:03:42,270 Well again first off we kind of prop the container by getting that file system ready. 48 00:03:42,430 --> 00:03:48,070 Then after that we actually executed the primary start up command in there with Docker start. 49 00:03:48,240 --> 00:03:50,130 Now what was with the dash right there. 50 00:03:50,130 --> 00:03:55,110 Well to show you what's going on with that let's try running Docker start again but without the dash 51 00:03:55,110 --> 00:04:02,260 a so I going to run at Docker start and then I'm going to again paste in whoops I lost the thing I've 52 00:04:02,260 --> 00:04:10,460 got to do the create again very quickly so there's my I.D. and I'll do Docker start but without the 53 00:04:10,460 --> 00:04:12,400 dash this time. 54 00:04:12,510 --> 00:04:18,620 So when I run Docker start you'll notice that I just see the I.D. The Dash a command is what's going 55 00:04:18,620 --> 00:04:24,320 to make Docker actually watch for output from the container and print it out to your terminal. 56 00:04:24,320 --> 00:04:30,200 So the dash 8 specifically means hey kind of attached to the container so to speak and watch for output 57 00:04:30,200 --> 00:04:33,680 coming from it and print it out at my terminal. 58 00:04:33,680 --> 00:04:38,960 So when I put on Docker start dash that means give me any output that is coming from that thing. 59 00:04:39,030 --> 00:04:41,200 And when I run that boom there it is. 60 00:04:41,210 --> 00:04:46,750 So you'll notice that's a very small difference between Docker run and docker start by default Docker 61 00:04:46,760 --> 00:04:51,770 run is going to show you all the logs or all the information coming out of the container by default 62 00:04:51,800 --> 00:04:58,100 Docker start is the opposite Docker start is not going to show you information coming out of the terminal. 63 00:04:58,420 --> 00:05:04,140 All right so that's the differences between Docker run and docker start hand Docker create. 64 00:05:04,180 --> 00:05:07,420 Let's take a quick pause right here for you and come back the next section and we'll talk a little bit 65 00:05:07,420 --> 00:05:13,730 more about exactly what it meant when we saw with the docker P.S. all that exited status. 66 00:05:13,870 --> 00:05:15,700 So quick break and I'll see you in just a minute.