Docker Commands With Examples | Docker Tutorial | DevOps Tutorial | Docker Training | Edureka

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
good evening ladies and gentlemen welcome back to a tariqas youtube channel my name is Vardhan and today we'll discuss the most commonly used docker commands and how they work so the commands that you see on your screen here they are the ones which are most commonly used so if you are a divorce engineer or if you're just someone that's working on docker then you might have already used these commands or you might use them in the near future some of those commands are darker version docker help a couple docker run docker build docker login docker push docker PS your PS stands for docker processes and this command is used to see what are the active containers currency and then we have docker images then you have dr. stop taco kill there is docker RM which has caused a stands for dr. remove docker RMI which stands for remove images we have docker x'q and this is used to access the bash of any active container and then we have two awkward commits we have docker import docker export the upper container docker compose dr. Swann and docker service so these are the 20-plus docker commands which are most commonly used now without wasting much time let me get started and discuss each of these commands dhaka version this command is used to find out what is the version of your docker engine okay so remember there will be two flags that we come in before writing version and then we have another command which is docker again two flags and then help now this is basically used to list down all the possible commands that you can use with docker so here docker will be a parent command and whatever child commands there are possible here as permutation combinations those would be lessened out now let me quickly open my terminal and execute these two commands for you do remember that I will be using my Linux virtual machine okay and and this next virtual machine of mine is an Ubuntu machine and it's hosted on my wii and black i said so and this is gonna open my terminal over here and the first command that we were supposed to execute is darker version right so as you can see the version of my dock origin is 17.0 5 ok so that's how this command works now the next amount that we were supposed to execute is docker help that of course would also come with two hyphens and like I told you there are radius commands that you haven't talked up like dr. a touch darker build proper comment dr. CP docker create darker diff so all of these are the other child commands that can be used with docker okay as a primary command so I hope that was clear and at any point of time if you people have any doubt with respect to usage of any command in docker then you can just use the help write and help will basically tell you the different commands are there along with a description so it also explain what each and every command does now let's say you have docker a build then you can see the explanation that it says build an image from a docker file right so that's a good enough explanation if I was a guy that's working on docker then I would know which option to use right similarly for everything so for docker RL it says remove one or more containers and then for docker for docker stock it says start one or more stop containers and many more so whenever in your free time you can use the docker health command and see what are the different commands possible along with their explanation okay so I am going to clear the screen and go back to my PPD and check what are the next set of commands that I can execute and remember these are all still basic docker comas okay so the next command is docker pull now the docker pull command is used to pull any image from the docker hub okay and then we have docker images command which of course lists down all the images in your local repository now in the previous command we do a docket pool right so for the first time you will not have any image in your local repository you will have to pull it from your docker hub and when you pull it from your docker hub it gets stored in your local repository and once it is there in your local repository you can run the docker image this command and then check all the different images so all the images would be listed down okay so that's about these two commands and then we have boqueron command now the docker run command is basically used to execute that image and I'm pretty sure you are aware that whatever you download from the docker hub are images right and you want a running instance or if you want it to be active then you have to run it because what you will have to deal with they are containers right I'll to get containers running then you have to basically run those images that's the same thing that we are doing here the commander's docker run along with the image name so supposing I am pulling at Kubuntu image from docker so I will be using this command docker pull Ubud - okay and if I want to execute this image and get a running container out of it then I would have to basically go here and run the command docker run along with that particular image named docker run Ubuntu okay guys so I think you have a decent understanding of these three commands now let me again go back to my terminal and execute these two commands will show you how they work so I'm back my terminal here okay so here let me write down the command docker pull Ubuntu now by running this command I am pulling the latest Ubuntu image from my docker hub okay so when you hit Enter in spite of the fact that I do not specify any tag over here as late as it's pulling the latest image that is available on the docker hub okay so let the process happen guys give it a minute perfect so now you can see the status here right it says it has downloaded on newer image for Ubuntu that is with the tag and latest now if I want to check if this image is actually been pulled then I can run the command docker images now let me run that command by fostering the screen and then actually running the command docker images when you hit enter like I said you have the entire list of images available in your repository over here the entire list is down over here correct so you have custom image you have version LS / custom image right so this is another image which I created if you want to check if your image is latest then you look at Kubuntu your right so this has a tag as latest and this was an image which was created ten days ago in my local repository and it is about 112 MB okay this is the one which we downloaded recently and it has the latest tag so this is how you check the different images that you have in your local repository guys okay so I'm going to clear the screen and now it's all about executing a docker image so for sample purpose I can even run any kind of an image and get a container right so before I execute an Ubuntu image let me execute a simple hello world continue so for that I'm gonna say docker run hello world now remember when we say docker run HelloWorld you might ask me a question that is HelloWorld already present in my local repository well the answer is it's actually already present so I have an image of hello world in my local repository but even if I do not have the hello world image in my local repository this command will run because when you do a docker run command this would first of all look for this particular image in your local repository if the image is not present then it will go to the docker hub and look for an image with this particular name and it will pull that image with the latest tag okay so run does two things it pulls and it executes okay so let me hit enter and there you go it says hello from docker right so this is the hello world container for docker now the reason I did not execute the Ubuntu images because I want to make a few modifications to that image but if you want to make a few modifications to that image then you have a different set of commands which are involved so let me go through those commands and then get back to what I was supposed to do that was about docker run and then we have something called as doc up build okay and this docker build command is used to build a custom image of yours supposing you have a Logan to image okay but you do not want it exactly as it is and you want to make a few adjustments to that so another example for that would be the node image right in my previous sessions I've had sessions on docker swarm I had a session on docker compose and many more right so over there what happens is I'm using an odious image as my base image and then I'm building my entire application on that so what you have your risk you have a base load image okay and on that note image you build your entire application be it an angular application or be it a mean stack application and the command that you use to build the entire application is the dock of build command and as you can see this is the syntax we have to say dock a build with the flag - tea and the tea flag what it does is it basically tells you that you can give your name with a tag for your image which are building because this image is going to be your image right your custom Lee building this image so when you custom build this image you can give it your own name and that's what this is and followed by that with a space I've specified a dot here now the dot specifies that the talk of file which is needed to build this docker image is present in the current directory where this command is being executed now had I specified the entire path of my daugher file then I didn't I wouldn't be specifying the dot over here right but in that case if I'm specifying the entire path then that means that my daugher file is present in some other location not necessarily in the same location where the command is being executed okay I hope that was little clearer you people so now if you're also not clear let me give you a demonstration and then you will be able to understand this in a better fashion ok so let me open my terminal again and currently we are in the slash home slash iterator directory now for the demo purpose I had created a new docker file let me first open and show you that docker file ok and that docker file is present in the Downloads demo folder of mine if I do an LS there is a dot the file perfect so let me say cat docker file in fact let me open this in G edit so sudo G edit docker file yes now the docker file is the most important file if you want to build your own custom images because whatever you want for the application to run those dependencies are specified in this file you have to save which is the base image that you have to first of all download from the docker hub and use that as a basis for your application and then you have to say the other commands that you want to run now in this demo of mine I am simply downloading and open - image from the docker hub and I'm just echoing this sentence hi this is version from a breakup so it's a very simple process right I am pulling one I'm going to image and I'm doing an echo on that particular image so you can just save this closes docker file and then execute this particular docker file okay and since I am in this folder I can use the dot to specify that the daka file is present in this directory now let me first hear that screen and then run that command again so the command is docker till - T let's give the name of the image as my custom Ubuntu image custom Ubuntu well that's good enough right and then I'm gonna say it dot because the docker file to build this my custom open - image is present in the same path ok so it says my custom open-toe should be in lower case ok no problem so let me just check my docker file once ok now the reason I got this is because my image name cannot be in caps so what I'm gonna do is let me read on the command with a different name possibly in small letters ok my castle we're going to okay perfect the command got executed so if you can see here it says selling the built contacts to the dr. demon and since ads specified only two steps in my docker file those two steps are being executed here step one is it's pulling the open - image from the docker hub and since I it's already there in my local repository it's using whatever is there okay and step two is running the echo statement hi this is warden from Edo rekha right this was the second step and the same echo command has been executed over here hi this is warden from Edo Rika correct perfect so I hope you guys got a good understanding of this particular command because this is the most important command if you want to make it as a divorce engineer or a person that's regularly working on docker because all of the images that you will be working on in your office or in your workspace you will have to be working on custom images for your application so remember the how this command is used and how the applications are built so let me just clear the screen and go back to my slides and see what is the next command in source rust okay so the next command is the docker container command and this docker container command is basically used to manage your containers now let's say you have n number of containers and because so many containers are active at the same time your system may be lagging right there's a performance issue so at that time you might want to close or n certain containers right kill their process so at that point of time you can use the container command and kill the container straight away so it's just one of the different options that we have so there are a number of other commands which can be used with the docker container as the parent command and I would request you to look up the set of commands on docker docks okay but for now let me just go back to my terminal and execute one of these commands and show you how they work so let me go back to my terminal here and here I'm gonna run that command docker container and let me run docker containers logs okay but so here let me run the command docker container logs to basically find out the different logs that are associated with my container okay now the thing is in arguments I have to specify the container name or the container ID and since I don't know it right now let me first find out what is my container ID okay so I'm gonna do a dock of PS command to list down the different containers okay there are no active containers so I'm gonna do a - a flag so these two commands I will explain in detail at a later point of time guys okay but anyways getting back to our problem here you can see that the hello world container word is secure it right so I wanna copy the container ID here and now I'm gonna find out what are the logs of this docker container logs and then I'm gonna paste the container ID this way whatever laws were generated for this container those would be displayed perfect worked as with the container executed again so the same thing can be done for any of the other containers okay if I do a docker PS - a and C there are so many other containers which are there right in my system I can copy the container ID of any of these and I can execute the same thing again and again docker container logs right and then I can paste this so this time the logs of this particular container which is nine one six and this entire ID this logs have come out and like I said with docker container you have various other options correct you have options like dr container kill you have docker container remove and all those things so I can use a docker container remove and hit enter and basically when I do that this particular container is off so if you remember this ECC right this container is the HelloWorld container and when I said RM this container is removed so if I go back and do docker PS - name then the first entry for the hello world container would not be present and yes as you can see it's not present right the hello world container is not present here now that's what I'm going to show you so I've go through in my screen and now let me get back to my slides so I basically executed the docker container logs command the docker container RM command so you have various other options like I said you have the container kill which can be used if you want to kill any one particular container okay you can use the docker container run command to start any container which has been temporarily stopped or which is inactive okay and if you want to again start the container found something that has been stopped you can use the dropper container start command and these are just a few of the commands and the entire list of docker container commands can be found in Dhaka docks okay so I would request you to go to docker Docs and then see the entire list of commands if you want to learn more about this command in the meanwhile let me go to the next slide and continue with our session the next command that we're going to talk about is the docker login command okay and as simple as it sounds this is used to login to your docker hub account can any of you guess why we would need to login well it's for the simple reason that you might want to push any of your image that you have created locally right so when you are working with a team who are all using docker then you can just pull the docker image or create and your dock remains from scratch at your end and build a container and if you want to share that container with other people in your team then you can upload it to docker hub right so how do you upload it to docker hub so if you want to upload it you don't have any other work around so you do it through the ER terminal and to do it through the terminal you have to first do a docket login once you've logged in using your docker container credentials then you can simply start pushing your docker image to the docker hub okay so that's why this command is really important so let me go to my terminal and show you this command the commander's dock and login when I hit enter it says login with your daughter Arya to push all the images from docker hub if you don't have a doctor ID it says head over to this website so this is where you can create a new docker ID okay and the username it says in brackets it says vertol NS that's my username because I'm already logged in so I'm just going to hit enter without entering the username again and the password I can enter is my password so that of course and rubble and reveal to your people but once you enter the password and hit enter then it says login succeeded right if your potentials are a match then you are successfully logged in and once you're logged in you can start pushing your docker images which you worked on locally to your docker hub ok perfect right so let's clear the screen and get back to our slides now like I said the next command is basically to push your docker image to your daughter hub remember the command should have your docker ID slash the image name ok my human to image this may be the name of the image that you might have created locally ok but if you would have push it to the docker hub you have to tag it with a name and that name should be your daughter ID ok so let me get to the ER terminal and show you how this command works so let me first look for the image that I want to upload to my docker hub ok so all I had docker images the list of all the images come out and if you remember my customer bun 2 is the name of the image which I created now let me try pushing this image to the docker hub ok so I'm gonna copy this and first clearing the screen and here I need to tag this image with my daughter riding right because right now it has the name my customer going to and I cannot upload it to docker hub with this name now since I have to tag it with my name there's a command called docker tag and here you have to specify what is the which image that you want to tag so the images my castle Ubuntu and here let me specify my docker ID slash the image name so I'm gonna say Vardhan LS okay no that's my daughter ID and slash my custom Ubuntu image right so this is the name of my image I can even change the name but I've just retained my customer bill - as the name of Mohammed so when I hit enter this image would be getting uploaded to docker hub and now this image has been renamed to warden NS / my customer window we can verify the same by running the command docker images and as you can see here there is there is one image with the name my customer one two and then there is another image with valdon + s / my customer board - correct now this is what I have to upload so now I can use the dock at push command so I'm going to say dr. push and then simply specify the image that you want to push doc a push button s slashed my customer burn - hit enter and the image would be getting uploaded to docker hub and once when you do it from your end after this command is executed successfully you can go to your docker hub and check that your image which you created locally has been uploaded to the docker hub and it can be shared and accessed by other people okay okay perfect so this shows that my image has been uploaded and let me just clear the screen and get back my slides and move forward and this command is something that I already a kiss killed it some time back where if you remember I use the docker PS command to identify which are the containers which are currently active in my system right and my daugher engine so that's what this does PS basically stands for processes and when you hit docker processes then all the container processes which are currently running in your dock region would be listed however if you append this command with a flag right then all the containers which are inactive even those containers would be listed down so that is the difference between these two commands to our PS and backup PS with a flag a now let me go to my terminal and show you that so dr. PS first okay and right now there are no entries because there are no containers which are currently active but if you want to find out all the containers irrespective of whether they are active or whether they are not active then it would list down all the containers in my system right in my host and that's what its gonna do doc appears - it and as you can see there's an entire list of docker containers over here there's the custom image which I created and then there are various other mangez over here which I used to build a container and I'll show you how they work in my previous sessions so the contact list angular and then there is a demo app one these were images which are used for my daugher swarm and from my docker compose video is respectively so if you want to go and see those videos then the link will be there in the description below guys and I would request you to go through those images to understand other darker concepts better okay because dr. Campos and dr. Swan they are the advanced concepts on docker and that's a must know if you want to make it as a docker professional the link for those videos are in the description below so let me just clear the screen and get back to what I was doing so the next command that we have is the docker stop command now the docker stop command is basically used to shut down any container so if there is any container in your dr. engine which is running right in your host and if you want to stop it then you can use this command and do note that this command would not be shut down right away it might take a few seconds because it would be gracefully shut down waiting for the other dependencies to shut first okay it's sort of force stop it's a very gentle stop that's what this command is but we have something called as a docker kill command okay and what this dr. kill command does is it ungracefully stops your container as in if there is any container that is actively running it would straightaway kill it in spite of it's something similar to force kill right so that is the difference between these two commands docker stop and docker kill kill would straightaway kill your command now before I show us all of this let me go forward and talk about a few more commands there is something called as a docker remove right docker RM this one what it does is it it removes a container at this point of time you have to remember that if you want to remove any container from your host you have to first stop it and how will you stop it by the two commands that I explained in the previous two slides you either for skillet or you kill it gracefully using the docker stop command or the docker kill command and once you've used those two commands you can remove them from your repository okay and we have another command that is the docket RM I okay so the docker atom would remove containers but if you want to remove images itself from your repository then you can use the talker RM come on okay guys so these are the four different commands that we have your which is our regularly used now let me open my terminal and show you how they work so us let me do a docker PS and since there are no containers which are currently active what I'm going to do is I'm going to start a service okay I'm gonna containerize a particular service and then I will show you how to stop it or kill it or remove it okay there is a one particular image demo app one okay which I used to deliver my previous session there was the docker compost session right over there I used that particular imager and I created an angular application so I'm going to first start that service and the command for that is docker run - - RM I'm going to say port number is 4 - w 0 colon 4 - double 0 because it's an angular application let's give it a name its - - name right so let's give it a name my angular application or let's give it a name my demo application ok and demo app 1 is the name of that image so when you hit enter first the image would come up right the image would be spun and the container would come up let's just wait for the container to become active so let me first open a new tab of this terminal ok and here let me run the command docker PS and you can see that whew 42 seconds ago this app was created right the demo app 1 here it says the web pack is compiled successfully so if I go to my Firefox these servers would be active the angular application would be active ok but if I want to temporarily stop this container or if I want to kill this then I can use those commands docker stop or I can use docker kill ok so let's use those commands and see how they work I'm gonna say docker stop followed by this container riding correct hit enter so the docker servers are stopped now if I do a docker PS command this container would not be active okay and over here also you can see that which was temporarily compiled it has ended right even the service is not hosted there you go so that's how the docker stop command works so let me go to this come on and restart the same service and over here this time instead of using the docker stop command let me say docker kill ok sorry I've just used the same container ID right so I needed one docker PS first ok and yeah now this is the container ID which I have to kill so I'm going to say docker kill pasting this container ID and a tender and that's container as also ended so even the service has exited from here right so that's how you kill a container that's the difference between the stop command and the kill command okay so I'm gonna go back to your screen and after these two commands there are two commands like docker RM and docker are am i right they are used to remove continuous and images respectively so let me go ahead and do that first let's run the command docker RM ok and now we have to specify which container you want to kill or remove so for that purpose let me first find out which are the different docker containers that are there in my system so when I do a docker PS - name there are a number of containers and from here let me remove this test angular container ok this is the name of the image and this is the cutting or ID so I'm gonna copy this container ID and go back here let me clear it and here let me run the docker RM with the container writing and when this is returned it means that my container has been deleted successfully and the benefit with this is I've freed up a little more space in my host right in my dock origin now guys are similarly we saw how to remove a container ok now let me go here let me know what docker images so this is these are the list of for the different images are out there in my repository and if I want to remove any of these images then I can do docker RMI and what we have here is we have a Redis image and we have an alpha and image which I do not need so let me copy this Redis image and remove this image from my repository so the command is docket RMI this type because remove image is what it stands for and I can specify the image name or I can even specify the image ID so image name is good enough so that's what's happening right it says untagged and deleted perfect now I can clear the screen and what I wanted to show you I've showed you already now if I run the docker images card again then the Redis would not be visible here so you can see alpha and but you can't see you Redis correct so that's how it works so let me go back to my slides and go to the next command we spoke about stop we spoke about kill we spoke about docker RM and we also spoke about docker or am I now the next command that is in question is the docker exit command okay and this command is used to access any active container write any container that is actively running if you want to access the bash of that particular container then you can use this exit command okay and we use a I T flag over here so you can either use - ID together or you can use - I space - team now what I does is it's basically it says access your container in interactive mode so that's the option this flag specifies and that's why we're able to access the container okay and you have to specify which container you want to access followed by the word bash so let me go back to my terminal and show you how that works so over here let me clear the screen and do a dock of PS and check which containers are actively drawing none of them are running right now so let me start a container over here okay let me do a docker in fact I can start one of the containers I started sometime back the demo app one right the one I spoke about is the angular application let me start this same container let's wait for it to come up perfect now it says a web pack compiled successfully so now let me go to my browser and hit localhost for to double zero because my angular application is at the one port number four to double zero right so this is that angular application which I was talking about so if I go back to my terminal you can also see that I have a specified photo double zero as the port which is to be used to access that application on my host and this is the port number it's running on internally in my container so I'm mapping my currently in a port to my host port and because of this I could access that angular application on my web browser now getting back to our slides we were supposed to use the docker x''k command to access this container right so right now I cannot access this container over here so let me access this container in a new terminal so this is the new terminal and here if I do the same dr. PS command the new container is active so from here let me copy the container ID and then run the command docker x'q with the flag IT followed by the container ID and then bash bingo so right now I am inside this container so all this time our this was the user right Enrica at the way to boon to this was my host machine and this is my username right now I'm logged in as a root user inside the container with the hub having the ID this one because this is what I specified over here so now we are not in my local system we are inside the container and what can we find inside the container we would basically find dependencies libraries and the actual application code of this particular angular application which is hosted over here right which you can see all the project codes would be present inside this container correct so let's verify if that is the case by checking if we are actually there and by doing an LS you can see all the different files here we have a docker file which was used to build this application and then we have a package dot JSON file which is the most important file to build any Android application or any main such application and then we have protractor dot corner of dot J's which is used to test any angular applications and then we have so many others right we have an SRC folder you have an e 2e folder and then we have no dress code module so this is where all your project dependencies are stored correct so package notation specifies what are the project dependencies that you want and this is where it's all stored so this is my angular application right so if I go one directory back I am in this SRC folder now okay let me do an LS I have a pure let me go one path back again and do an LS and you can see that I have other folders like bin games include Lib local has been shared and SRC now all these are inside my container I hope this was enough evidence for you I hope it was so I'm back here and yeah that's how you access your container if you want to make changes you can make changes you're okay and since we are inside the container let's just create a new file so let's just say touch F one so the touch command is used to create an empty file right so now if I do cat F one of course it is nothing but let me do a pseudo G edit okay so I don't need to give a sudo because I'm already logged in as root user swamis gonna do G are at F one okay so it's not letting me access this command right okay guys anyways that's how you access the container okay so let me just clear the screen and if you want to exit the container exit the bash then you should use the command exit so when you hit exit you are back as the Erica user on your open to host system interesting right so I'm gonna clear the screen and go back my slides and check what's next and then we have the docker commit command and what this docker commit command does is that it basically creates a new image of an edited container on the local repository in simple words it creates a new image of any container which you have edited correct so let's execute this docker commit command and see how that watch let me go to my terminal here let's first run the docker PS command a check this is the container ID I access my docker container so I hope some scenes would have been there so let's create a new image of that particular docker container okay so I'm gonna say copy and run the command docker commit and then specify the container ID of your container and followed by that you have to specify the name of your new image so I can say Vardhan NS / my image right my angular image so this would basically create an image of this container which is running and bingo perfect it's done so if I run the command docker images then there will be a new image with this name and tag let's verify that by going to docker images let's go up and as you can see there is version anis slash my angular image perfect this is what we wanted to verify correct so let me clear the screen and go back here and yes the pack has compiled successfully this was the message we bought earlier so anyways let's all worry about that that's what a docker command does so if I want to stop this container service then from the new terminal let me just kill that container service correct so this is the ID copy this and then I'm gonna say docker container stop and my container would have stopped so here yes my service has stopped over your bingo so I'm gonna tear the screen and both the places okay now let me get back to my slides so the next command that we're going to talk about is the docker export command correct so the docker export command is basically used to export any docker image in your system into a tar file correct so this tar file is going to be saved in your local file system and it's not gonna be inside docker anymore this is another way of sharing your docker images right so one way was by uploading it to docker hub but in case you don't want to do that you don't want to upload it to talker hub because the image is very heavy so that is this is an alternative which is our use in the industry where we do a docker export from one machine and we save that image as a tar file and this start file is imported inside the destination system and over there it can be accessed again and the container can be run so let me show you an example of that by first of all getting to it okay so it says docker export right so this is the syntax for that okay you say docker export you use the output flag with two hyphens you can specify the name of the tar file that you want to store it with and then you have to specify your image name or where you are okay so the amazing over here is my container so you'll have to specify your image name so let me go to my virtual machine and what are the docker images that I have available there is Bahrainis slash my angular image there is my customer bun too so what I'll do is let me save this my custom Ubuntu image okay this is my image and the image ID is this right so I'm gonna copy this go back to this terminal and what I'll do here is I'll say docker export double - which is the flag I'm gonna say output flag is equal to I have to specify the name of my tar file right so my docker Todd file I can say I can say that my daugher dart file and your after specify the container and name so docker images wouldn't do for that so I'm gonna do a doc of PS - a so I have a custom image here right so let me save this particular image so I'm gonna copy the content or ID copy this and paste it over here which indicates that I will create a fine of this particular container and this tar file would be same in this repository itself in arica at the rate I'm going to now since it's a heavy container it's going to take a few seconds and it's done and we can verify that by doing an LS the name he gave us mine darker tar file correct and then you can see there's a my docket art file which is basically a pgz file so if we go back to your documents you can see that there's a new tar file my daugher tar file that was created and you can verify the same my docket art file over here this is the newly created tar file so I can go back to my you're on a larger screen screen okay perfect so going back to my slides I've shown you how the docker export command works and what's the benefit now in the next slide we have the docker import command now the docker import command is basically used to import any tar file if you have any tar file which has been given to you by your cell developer and if you want to create a container of that one then you have to import it right so how is that possible so this is the syntax for that the command is docker import and then the complete path of that demo file of that tar file ok so for this particular purpose I have already created one tar file because I wanted to create one which can be imported very soon so I created a tar file over here demo tar so it is present inside my downloads folder correct so let me import that file so I'm gonna say docker input and then I'm after specify the complete path so it's slash home slash a Drakkar /downloads slash demo tar let's hit enter and this particular image has been successfully imported you can verify that by saying the first few characters of the newly created image okay so let's run the command docker images over here and you can see that just recently 23 seconds ago a new image was created right with the same image re 2 3 EF and it is the same image id over here right it starts with the same sequence characters and right now it has no name so that is how you easily import docker images ok we first export it and then you can import it so let me just clear the screens of both the tabs and now getting back to my slides I'm down with my docker import command and now comes the advanced docker commands okay so after you hard we saw the docker commands which are very basic and you know which can be executed easily but here comes the challenging part docker compose and docker swamp right these are all advanced concepts in docker which solves a lot of business problems and of course the commands are also little advanced in nature so first let's start with docker compose you know there are two variations to it and the two syntax can be seen over here docker - compost build and docker - compost up so these are the two commands which work very similar to docker build and docker run right so docker build is basically used to build a new image from a docker file correct similarly a docker compose build is used to build your docker compose by using your dock and Yama file now your file stands for yet another markup language and now in the Yama file we can specify which old containers we want to be active okay and you have to specify the path of the different docker files which will be used to create those containers or those services and that's what docker compose does right it creates multiple services and it's basically used to manage all those services and start them at one go so it would use more than one docker file probably if you go through mine your previous video on docker compose have explained it in detail over there I have used three different docker files and using those 3d aquifers I have created three services right and the three different services are the angular service the Express and node service and the MongoDB service the mamata v was used as a database the Express and was used as my back-end server and angular was used for my front-end okay now the link to this video is present in the description below okay but let me just quickly wrap this up by saying that if you want to build that you use the docker compose build and if you want to start your docker compose and start the container service then you can use the docker compose up this is very similar to the docker run command okay and that's what your docket compose does right it creates multiple docket services and continue Rises each of them and gets the different containers to work together so perfect let me go back to my terminal and let me do that for you so docker PS there is nothing so right now we are in the home slash andraka folder correct so let me do LS and there is a folder called means that cap so I'm gonna CD into this particular folder and here if I do an LS you can see that there's a docker compose dot Yaman file so let me do a G edit docker compose dot yah will file so over here you can see that I have specified the commands to create three different services one is the angular service other is the Express service and finally my database service okay I have explained all these things in my previous video I repeat the link for that video would be in the description below okay so let me quickly execute this Yaman file okay so if I do a docker compose build then this command would look for this docker compose file inside this directory okay and then it would you know once this image is built I can straightaway execute that command by using the docker compose up okay so I'm just gonna replace build with up this way my docker compose would also be up and running earlier I showed you an annular application and this time is going to be your entire bean sack application which is what I involve for everything mobo DB express angular and no GS so my express is up and running my angler is up and running my mom gonna be is active on port number two seven zero one seven Express would be active on foot number 3000 and angular as usual would be active on port number four to double zero so let's verify the same by going over here okay it also says the pac compiled successfully so this time if i refresh this there's a different application that would come up correct so this is my main stack application on port number photo double zero is the front end on port number 3000 this is my server end which simply says fubar and then on port number two seven zero sorry zero one seven there is my MongoDB right so these are the three different services which are active on my wheels port numbers so going back to my terminal I can do a docker PS to verify that there are three different services of mine which are running now if I want to stop each of these services I can simply do a ctrl C from here and hopefully it stops yes all three sources have stopped let me execute the same command and this time yeah they're all gone right so the docker PS command shows no containers active bingo so I'm going to screen out okay and go back to my slides and go to the next come on and the next sort of ODS come on that we have is the docker swarm command docker compose I told you was to basically have a multi container application right and docker swamp is however used to manage multiple docker engines on various hosts right so usually you might be aware that your docker engine is hosted on one particular host and you're executing your doctor commands over there right that's what we were doing all this time even dr. Campos did that on the same host three different services were started but with docker swarm the benefit is that we can start those services in multiple machines so you will have a master machine which is nothing but the docker manager as visible from here and then you will have different slaves or the charcoal as worker in docker terms so you have a manager and workup and whatever service you start at the manager will be executed across all the machines which are there in that docker swamp cluster okay so it says right it creates a network of docker agents or hosts to execute the country in parallel and the biggest benefit offs for dr. swarm is scaling up and ensuring high availability okay so some of the commands which are associated with dr. swarm are these if you want to first false start off creating a docker swarm then you use this command docker swarm in it and you say advertise okay and then you have 192 168 dot one dot 100 it's supposed to be two hyphens over here okay yeah so this is how the syntax is supposed to be docker swamp in it - - advertise - add up and then you have to specify the IP address of your manager machine so if I start the swamp from this particular force of mind then this would assume the role of my manager okay and in this syntax remember after specify my own IP address so that the other workers who will be joining my network would subscribe to my IP address over here so let's quickly go and execute this first command and let me show that to you okay so let me open up the terminal and the command is docker swamp init with SAS for initialize with the flags advertise adder and then the IP address su of the IP address of my VMs 192.168.1.1 hundred okay so when I hit enter see what happens it says swarm is initialized and this is the current mode this particular node is now one manager okay and if you want other machines to join this particular manager as workers then they have to use this token so we have to just copy this go to the other machines and x-cubed supposing this is another machine of mine okay I'm giving you an example so over here you would have to paste that token okay so this is called the token you just hit enter and then you will join as a worker okay so that's how the docker swarm command works now I cannot go into too much details with respect to how docker swamp works okay because there again it will take a lot of time and if you want to actually learn docker swamp you can go and watch the other video which I delivered a couple of months back right that video is called docker small for high availability okay and that is a detail the video and you will enjoy that video because with that video I've shown how docker swarm can be used and you will see the power of docker in that particular video so I would request you to go there and the link for it is again below in the description ok so I would request you to go there if you want to learn more about docker swamp but getting back to our slides they have other commands you're right so the docker swarm join is what I already explained to you so followed by this you will have a token so if you give that you can join a particular swamp cluster as a worker ok so if you want to regenerate that particular token which is needed to join that particular cluster then add the Manzo's end you can execute this command docker swarm join token so it would generate that open and give it to you and so only if you want to leave the docker swarm cluster then you can execute this command docker swamp leave ok so if you execute this command straight away at the workers end or the nodes then it would simply leave ok but add the Manzo's end it would not leave just like that you'd have to append the flag force so let me show you that let me just execute the command docker swarm leave if it was a worker it would leave right away but since it's a manager like I said it says use the force option so let's use that ok docker swarm leave with double flag force and it says the node has left the swamp perfect right so this is all about docker swarm guys ok so let me go back to my slides and covered the one last command that is that for today and that come out is the docker service command so this command is used to control any existing docker service beat any container or we get a docker compose or docker swamp or anything else right so Tocker services are very underutilized command I would say because if you want to control your different nodes when you are in a docker swamp then you use the docker service you use the docker service command to list down the different nodes that are there in your cluster you use the docker service PS command to find out what containers are being executed in a particular node and then if you want to scale the number of containers supposing you have a cluster of five machines and then you have five containers running in each of those machines if you want to scale those containers to 25 that means you will be executing five containers on each machine right so for that you have to use the command docker service scale if you want to stop any container on any particular node then you use the command docker service stop and then if you want to find out the different logs then you use the command docker service logs docker servers RM and so on right so the docker service command is let me repeat it's used in sync with your docker swamp and docker compose primarily so that's why these form the advanced docker commands so let me go to my terminal and quickly show you a glimpse of this so its docker service if we do an LS you will not have any options listed because it says this is not a swamp manager currently but if I start my docker swarm and then if I run the same command docker service LS then you can see that the output is different right I have few attributes your ID name mode which is basically details about the different worker nodes in my cluster but since no worker has drawn my cluster - there are no integer so that's how it is so let me just end that so that is the docker servers LS if you want to find out the logs then you can do that - docker service logs so if you use the docker service log you have to specify which service you want to check the logs off and what is the task right so which tasks and rich service so it's that simple guys so that's how docker service is used okay guys and again if you want to stop any servers if you want to remove any servers you can use these commands doctor service stop or doctor service remove and yeah that pretty much brings an end to my session all right so on that note let me conclude today's session and thank you guys for watching this video till the very end if you appreciate the work that is put into this video then I would request you to like the video or comment if you have any doubts comment or whatever you have to say and share that video with your friends and foremost please subscribe to enter rakers youtube channel and then you will be notified of any events in the future right if there is any new video that we uploaded or if there's a really live event then you will all be notified so please do that and I think it's thank you from my end okay so I'll see you next time happy Lloyd I hope you have enjoyed listening to this video please be kind enough to like it and you can comment any of your doubts and queries and we will reply them at the earliest do look out for more videos in our playlist and subscribe to Ed Eureka channel to learn more happy learning
Info
Channel: edureka!
Views: 73,135
Rating: undefined out of 5
Keywords: yt:cc=on, docker commands, docker commands with examples, docker tutorial, docker training, docker tutorial for beginners, devops tutorial, devops training, docker compose, docker swarm, docker pull, docker run, docker build, docker push, docker login, docker container, docker images, docker import, docker export, docker exec, docker commit, docker service, docker networking, docker edureka, devops edureka, edureka
Id: lktzQrHQcYU
Channel Id: undefined
Length: 55min 34sec (3334 seconds)
Published: Tue Feb 06 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.