Info |
---|
Welcome back. In this day let's look at the different commands which are related to containers. In the previous tape we played with images. This is where we would be playing with containers until we have been running a command Dr. Ram hyphen B five thousand five thousand to load up no JS application. Right so the interesting thing is that this command is actually a shortcut so it's a shortcut for docker container. So instead of being a darker container than we have been doing Docker run until now. So whatever we are doing or here is actually running a container from this specific image. So docker container run is used to run a container to create a container from image. Now let's look at all the containers which are running at this particular point in time docker container. Unless you can see that we just have one running container right now. We already saw that docker container a less hyphenate returns all the containers irrespective of their status as it shows both the exited and the running containers. So let's do a docker container list to see these running containers and what I would want to do is I would want to play with the specific container if you look at the specific thing right now if I do a local host five thousand yeah you can see that Hallowell. What we can do is we can pause the container as well so I can see docker container pause and passing the idea of the container the idea of the container is a 3 to 2 8 3 2. So let's do that again. We did a docker container pause A3 to do a container. Unless you can see that it's now in the status of paused what is supposed mean it means that the container will not solve any requests. So if you do a refresh you'll not get any response back. It would just hang and it would time out after a little while. Now the opposite command of pause is to do on pause docker container and pause eight three two. So if I do that right now and do a refresh you'd see that I would get the response back so you can pass the container and I'm positive. You can also stop a container. So if I do a docker container stop 8 3 2 what what would it do. It would stop the running container so let's do that to dock a container stop a three to this is something which we already executed a few times it's taking a little while and within a little while you would see that the container is stop. If I do a docker container else you'd see that there are no containers which are listed right now. Now there is another interesting command called docker container killed. So what is the defense boondoggle container kill in docker container stop. Let's look at an example. So what I do is I look clear and I would want to launch up a Java container a docker container to run. So we are using the full command right now introducing Docker run we are seeing docker container run and I launch it up in a detached mode and none of the containers are running right now. So I'll publish I'll publish it to port five thousand and the container port is also five thousand and the container image is in 28 Min slash hello world Java Cola Zero point zero point one dot release. So let's launch this container up. Earlier we deleted this image from our local machine. So it's actually pulling it again. So it will take a little while for it to pull it down. You'd see that after the images pull it would launch up that specific container. What we're trying to do now is try to understand the difference between a kill and a stop. What we'll do is we'll try and stop this container once and we'll try and keep the container went and see what is the difference between those two scenarios. So now we are refining that specific container. So if I do Docker logs hyphen if we are following the log stealing the logs for that specific container and you can see that the rest Web applications is started up. Now I'll open up a new tab so I'm opening up a new tab and what I'll do over here is docker container Alice and this is the container 80. So what I'll do is docker container stop and give that 80 and Ethernet I press enter I'll move into the other tab and you can see that there is a little bit of action which happens after I stop in Java applications to you are talking to a database you might have a connection which is already open. So it's actually giving the application a chance to close all that stuff down it is closing the J Max registered beans and it's shutting down the Executive Service so the application is shutting down gracefully. So the application is given time to shut down. Now let's launch under the container the same container again so I am using the same command which we used earlier to launch this container again. We have a container launched and now what I would do is I'll do a docker container kill before that work will I need to know the idea of the container of a container unless it's to a darker container. Kill and kill the specific container. You can see in the logs right now before killing let's follow the logs dock or contain logs hyphen F and paste the idea of container. So we create tracing. I mean we are following the logs right now and you can see that the last log which is present is this. If I do a docker container kill immediately the container is kill and you can see that there is no log after that. So if I do a docker container logs follow that you'd see that there is no log after the specific thing. So the application is not really given time to shut down gracefully. So docker container stop would give some time to the application to shut down gracefully and docker container kill will immediately kill the application. Actually if you talk in technical terms when we do a docker container stop what is happening is we're sending a signal to the container called Sig down ASI g the E R M and when we are doing a docker container kill the signal we are sending to the container is Sig kill sic kill means stop everything and drop dead. Now there are a few more interesting comments related to the containers which we would want to look at. So let's quickly do that a docker container unless there's nothing running right now. So let's do a document nevertheless hyphen and pick up the idea for one of the Java containers. Let's pick up this one up and let's do a docker container inspect so earlier we did a Dockery maze inspect similar to that. There is a dock a container inspect as well. So with the docker container inspect you'd be able to see a lot of details about the container. You can see the idea of the container you can see when it was created and what is the current status of it. Which image it is created from. You can see the details about the platform that it's based on Linux you can see the different port bindings which are present in here so we are taking the port five thousand from the container and exposing it on the host at the port 5000 and you'd be able to see a lot of other details about this specific container. We'll talk about networking in depth a little later. You can also see the networks that this specific container is part of. You can see that it is part of something called a bridge network. We'll talk about those that stuff little later but the important thing for you to understand is the fact that we know you have some problem with the container. This is what you might want to do. You want. You might want to do a docker container inspect and look at the details and see if you can figure out what's going wrong. When I do a docker container a less hyphen a I see that there are a lot of containers which are present in a lot of them. Stopped and I would want to remove all of them. How can I do that. The way you can do that is by saying docker container prune and c enter and it says this will remove all the stop containers out. Yes and it's deleted all the stopped containers. And if I do a docker container a list right now you can see that there is none of these present. Actually I should do a list hyphen. And even then you would see that there are no containers which are present in here in the state. We looked at a number of comments related to containers. We looked at how to pause and pause. What is the difference between stop and kill. How do I look at all the details behind the container by using an inspect. And how do we and how do we do all this top containers using Docker container. Broome I hope you having an interesting time and I'll see you on the next day up until then. Ray. |
Page History
Overview
Content Tools