Downloading Docker Images and Running them as docker containers

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I'm Patrick Bailey with whiteboard cutter calm today is April 11th 2017 and in this video me going over how to download docker images and run them as docker containers ok first some wording in nomenclature now if you're used to Amazon Web Services or ESXi or any kind of virtual kind of system you have a you have images and you actually have running instances so an image if you look at Amazon Web Services as an example and go in there you can find images you can find in a bunt to sit you know for image or a Windows image and that image is can't let your base it's immutable it doesn't change but it just sits there it's the image it's that's kind of what you copy over in a sense copy over and now you've got your own copy of it and then now you run based off of that now when you run that it's no longer called an image it's called an instance it's now you're running an instance based on that image now docker has half that nomenclature so a docker image is an immutable thing and so that is your your docker machine I guess and they call it an instant they call it an image but now when they run it they don't call it a docker instance they call it a docker container so sometimes it gets confusing when you say a docker image in a container and some people will switch the meaning the word between the two but the docker image is your immutable image similar to Amazon Web Services and your docker container is your running instance just to give hopefully that clip in everyone's head now with that whenever you're pulling down images the default is actually to pull them down from Dockers repository and that's at hub docker calm now if you go there and you go to the Explorer section you can actually have an account here and you can go through and you can upload images here that are publicly available but you can also go through and see some official images like here's an Indian x1 and you can kind of see and click on those and we up on them but that's actually where by default you're pulling down all your images from the official docker repository so with that let's go pull down some images so if I go into a docker machine here and I go see it was a docker to the doctor or pull I'm gonna pull down the Indian X image so I'm gonna pull it down it's gonna go talk to there if I it's gonna see if I have it locally if I already downloaded it I already have it but I haven't it's gonna go down there and pull it down I'm gonna pulls it down it actually has multiple layers which I'm not gonna go into right now but if you see multiple layers don't fret this kind of normal little kind of wish then you're downloading pretty noble dead layers I'll let this guy download okay now typically it's a little faster than that my connections a little slow right now and also engine X is a little bigger than most images what images are you know 5 10 Meg's in sighs I think it's ones more like a hundred but now that I've downloaded it it's not running I just I've downloaded the image so I kind of innocent I'm talking in virtual server terms I have the virtual server image I have the docker image just here but I'm not ready yet running it so now if I do do sudo docker images it'll display all the images that I've downloaded now here I made sure to wipe them all out so as I download that one now I only have one and so I can see your mix a little wider I can see here's the nginx image it's the latest tag they actually do tag these so you actually can get different versions so the latest I go up there and look right now let's go do that and go here and go to the official nginx repository click on there and go in here and see and I can go look at the tag so I can go look and see right there it says latest so they're version 1.1 1.1 3 1 11 13 that is the one I'm getting they tag that with latest and in this case in do next is officials this is a stable build not a future build or anything like that so when I download latest I'm getting one 11 13 now I'm not gonna go into in this video but there are ways where I can say you know what I don't want the latest which is the default if you don't specify it you can say I want one 10 3 or I want I guess this isn't quite stable and then my guess I could have said stable but that's there's a good reason you wanna look at these because latest sometimes means that's most stable sometimes it doesn't so here it's not they consider 110 3 stable I guess but that's a good thing to look at to see what you're actually getting but here latest is 111 3 and so here I've got the latest and you can download multiple ones so I could I'm not gonna do in this video this but just to let you know it's there so now I've downloaded that so another thing I can go download another one I'll go pseudo doctor pull and I'll pull Postgres and again since I didn't designate the tag it's gonna pull the latest and now Postgres has a lot of layers to it the good news about layering is when you if you already have a layer it doesn't need to pull it down again so there's that convenience but in this guys don't have any of them so well let it pull down there we go so now if I do sudo docker images as you see - so I have both of those so I've got the post press in the engine acts and you can see their size there that rather big by comparison so now next how do well actually now that I've pulled them down how to actually run them okay now running them so now that I pulled that down I could run in Gen X I could do sudo docker run in Gen X and that would run but the problem is nginx need to listen the docker image wants to lift when you when you turn the docker image into a docker container engine X wants to listen on port 80 but the containers don't have access to the outside ports they would just be there by themselves doing nothing so it's a little bit pretty useless in this case because it's not gonna do it it'll run and then it's listening and no one can possibly talk to it so you can do a port so if I do this that says port local port 8080 attach that to the doctor port 80 and so I can write like that and so now you run it it's actually running but nothing much going on because no one's talking to it and so right now I ran it in such a way that I'm attached to it so to show what's going on here I can go over here and I can do a couple of things I can do a do sudo docker PS and that'll show me that that is running so I have that this now is the container the container has a UUID unique to itself this is actually only part of the UID it also has given when it was created was given a name because I didn't specify a name it kind of makes a random name for it and also we can see here it doesn't it what's ports it will listen to it actually will listen on port 443 but we didn't pass that one in but we can see here that local IP address and port 8080 is listening is 40 into port 80 on there so we've got tapped up those together but now over here I can do curl local host 8080 and you can see I get out of here I get my my web page but also over here I'm getting the log file put out and it's typical that log files are gonna be sent to standard in and standard out they're not going to be sent to their own log files that's typical docker ISM and so there they are now so I keep doing that and get a bunch of them now it is true in this case we that you can run a docker machine without first pulling it down now in this case we pulled them down to they're available and so when I go run them they get created really quick but I could have done this I could have done a sudo docker run I'm gonna choose another image I'll choose hello world which is a small one that runs pretty quickly and I don't have this so if I do sudo docker images again you can see I still only have those two images is to only have it recorder I still only have Postgres and nginx so if I do a sudo docker run and I don't do the pool first it's going to try to run it but it can't see it it'll pull it down so you don't have to actually do a poll you can just do a run it runs it and this pulled it down so you can see pulling and then you can see it ran it and in this case it runs this one runs really quick and exits because it's not doing much but just proving it if I do a sudo dr. PS I can see I only have one running machine if I do a sudo docker images I can see yeah indeed it did pull down the hello world so you don't have to pull things but it's up to you you can pull the thing to run em or you can run them and they will be pulled down but just know that if you run things you don't have them yet it may take a second to pull things down okay now that I have it running I'll do is fill docker PS to show us running how do I stop it well I'm in this simple attached State so one way to stop it here is just do ctrl c ctrl C kills it and when I kill it I look here at sudo docker PS it's no longer running I can run a curl and just nothing there so that's how you stop it now typically you're not going to actually run things like is running it in this simple attache state is not typically a get run anything but if you do for a test and you want to kill it control C kill it but now that we've done that since you know if you in the Amazon or virtual world if I made a virtual machine from an image and that machine is now running and now I stop the machine running which is kind of what I did and I killed it the machine if I if I stop a machine and Amazon Web Services it still exists and just because I've stopped or killed this running machine the machine actually still exists the container exists so if I do a pseudo docker PS you know I see nothing but if I do is to do a pop pseudo docker PS - a which kind of means all that will show me all my running machines and all my machines that are not running that are in a exit state so here I can make this a little wider than C so you can see the status of these is exited so both of these if they exist but they have been exited so that's interesting to note so now next I'm going to show you how to start a machine in a detached state okay how do you start a machine in a detached state pretty easy I do a sudo docker Ron - dd4 detached and I'll do the same thing here 80 80 80 and nginx now in this case I'm making a new machine when I run it I'm creating a new container so those other containers even though they're in there stop state that they still exist they're still there but they're not running so it's not a problem to run this guy now when I do that I get the e the unique ID UID for that individual container that we just started and so now if I do a sudo docker PS I should see that it's running and there it is as burning for one second and the port's attached so now if I do a curl again I should you know hit it but now I'm not attached so I don't see the logs coming out but there it is so now I've got that one if I do a sudo docker ts a I can see the three containers I can see the two that are exited that are stopped and I can see the one that's currently up and running I just want to see the running one I can do that well now there's running it's a never-ending a detached state how do I stop it so I can to stop it I can do sudo a docker stop but what do I stop I need to know who to stop and there's two ways - there's two one two things you need to know you didn't know that the containers name in this case we didn't give it a name but they gave us they generated a name for us in this case called festive le on the other what other thing you could know you could use as an alternative is you could use the UID now this UID is very long and here's a shorter version you don't need to use the entire UID you need to use enough of it to be unique compared to your other containers and if you're only run in three or four containers you probably only need you know two or three characters to even be unique like in this case if I do you know sudo docker PS - and we look at these IDs I got d09 a and B B in this case D 9 and B are all different so I could say sudo docker stop D it would work but in this case I'm using a pseudo docker stop festive at all you know and that should stop it so now if I look here nothing is running okay so that's how you start a container in a detached state and then how you stop it next I'm going to do starting these stop containers how do I stop start restart these containers that are now in a stop state okay so now everything's stopped you know I got that sudo docker PS I was running again we can see nothing running and I can do a sudo docker PS a and I can see all the ones that are in a current exit status now how do I get one of those started up again pretty easy same thing I can take either the name of one or I can take enough of the unique ID to be unique and I can do sudo docker and in this case I'll do festival iam just a all and start that guy and now for us to do dr. PS as you see that festive a Leon is now running and I could do a curl against it and it's working just fine now that that's running let me see let me start another one and I'll show you a little problem with trying to start another one in the manner that I'm doing it so if I do sudo dr. start and I take one of the other guys I'll take a 9 a which is the elated Euler I'll just use the UID this time so I'll do 9 a which is enough of the mankini KT to be unique and I have to start which should have not worked ok what did you work on mine does not work why are you working I didn't give me an error maybe that's been on air what I did maybe I'm being mistaken here did do my notes on there oh no I did not yes but anyway I start trying to start this second one but I couldn't do it now I couldn't do it because of the ports and so here festival Eon is running but elated Euler is not running because I tried to start it let the ports you know that's I think that's why I do it you know I try to do that's why what I did I try to do is to a start P if I don't think it respects not as a respect any port in your starting when you start the original ignition initially run these you define what ports you're listening to and then currently when you try to restart them you can't change what ports listening to that may be a feature that comes someday but right now you can't you're stuck with how you started so if I try to start that again I get that message but if I go look at here which I thought I got an air before but I guess I'm mistaken it actually did not start no it did not start what if they'll tell me yeah no okay it did not start because it's listening on the same port so this ports already taken so it cannot start on that port because it's already in use so the only thing you can do is you can kill him so I could do sudo docker stop and I can stop a festive ileum and I can see they're all stopped and then I can try to start elated Euler again and now he should be running he's not oh sorry aha there's a reason there's not an error there because I was looking incorrectly so my elated Euler is not my nginx it's the hello world so of course it can run just fine oh I did give an error before so I'm being I'm not paying attention let me go back let me go back and start festive le on which is listening on port 8080 so that is my nginx sorry about that so that's listening it's working Colonel works just fine but now if I try to start fervent ride that's the one I want to start up so I'll do sudo docker start now do fir fervent ride there we go so now if I start that I get a failure there we go I know I'm not crazy so I'm gonna fail you because it's trying to attach the port 8080 which is already taken so I can't do that because the first one is taking it now normally there's no problem with restarting multiple instances it's just in this case there's a conflict and right now there's currently no way to correct that conflict because I can't reassign the ports on this at least not yet maybe that's a feature they'll come in some point but yeah just like I accidentally showed before I can start another server so I can start that hello world the elated Euler just fine and it runs because it's not in conflict with other guy but like I was trying to before let me go kill that's gonna do sudo docker [Music] stop now stop festive let me use the notes to zero I like use the UID or just D in this case that's unique enough so now that's been stopped doctor yes I think and I can see it is exited and now I can start fervent ride and it should start just fine and there we go it's running so that is about it for this simple video make sure yeah so that's how this I don't want to get too complex for a first video so this is how you can pull down images how you can run those images how you can run them in an init in a detached way and how you can start and stop them so kind of a simple intro I'll probably doing some more videos but this is kind of a start thanks for watching I hope you liked the video if you did please give it a like to subscribe just click the subscribe button also you can follow me on twitter under the handle at white board code or comm view any code i may have thrown up as a gist at github under the username Pat man Denver or check out my blog site at white board code or com
Info
Channel: whiteboardcoder
Views: 4,988
Rating: 4.8904109 out of 5
Keywords:
Id: 8G81HqZwY5w
Channel Id: undefined
Length: 20min 25sec (1225 seconds)
Published: Tue Apr 11 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.