Most asked docker commands to Java Developer | Interview Questions | Experienced | Code Decode

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to code decode today in this video we will be looking into very important Docker interview question that is the docker commands that you have used while building or dockerizing your spring boot application so let's get started and see all those commands which are bare minimum requirement for any application to be dockerized into a containerized application so let's get started please like share subscribe and comment so that this video reaches to more of the people who are preparing for interviews like you now whenever you install a Docker the very first thing that we need to do is to see what is the version of Docker so for that the command is Docker space version here we have already seen in the first video when we were covering the interview questions that Docker comes as a client server architecture now all the version information its architecture OS everything all the information about the docker that you have installed in your system comes with this command Docker version so when we put a Docker version you will have client version you will have server version and you have many many more information that is required that is configured with a Docker that you have installed the second command is how do you get the number of containers running paused and stopped so you need to know the containers so the command for that is Docker info tells you all the information about the client and the server now on the server it says you have 10 containers one running zero post nine stopped you have 41 images what is the storage system these are basically volumes the plug-in information the CPU usage total memory used what is the name the proxies many many things you can know with this command and also the number of containers running pause and stop you can see here itself so in the server you can see the number of containers which are running pause in stock so this was all about the docker that you have installed now if interview ask you give the information about the docker version you have installed or the containers that is up and running in your system without any UI or GUI then this is the way to do that now comes the real commands which will be used while you are coding or dockerizing your application so the first thing is to how to build an image so what we did was the first thing to create a Docker file now how to create a Docker image from the docker file the command is Docker build and the path to Docker file so I'm going to clear the screen and let's see now this is the path or the location where my Docker file is so how to create an image for this code decode project named as Docker the way to do is open CMD here and build the image with this Docker file so Docker build now this Docker bit requires one argument and what's the argument the name of the image that is basically the tagging of the image and the path where that has to be created that is the source of the root folder so Docker build space minus t which is going to tag your image name now since we are creating this image in May I am going to tag it with the namespace the namespace is the docker Hub namespace where do you find this Docker Hub namespace this is what is the namespace what you see here is a namespace so you have to select your name space then the name of the image the version and this dot is the web this image has to be created so I'm going to create this in the root on the source folder now doing an intern will build an image for us so you can see this is how you build an image when you have a Docker file available without these commands you will not be able to dockerize your application now here it says this image is created and can you see in the docker Hub this is the image that is created in Docker with test me version is 1.0.0 so that is how you create your image using the docker file when you have worked with your image how would you push it to Docker Hub now I have my image here this is created I want to push it to Docker Hub what is the command for that so command is Docker push your username and image name so that's Docker push your username image name this is going to be it says Docker push your namespace or the username and your image also with the image name you have to put attack otherwise it will say it will take it as latest and which is the default one so it will not be able to push so always remember when you push to Docker Hub what you need to do is Docker push the name space and the whole name of an image with the tag then only you will be able to push it to the docker Hub this is push with code decode test main when you go into this this is the tag 1.0.0 that you have given and it is pushed a minute ago so this is how you push to your Docker Hub and now you know that why I say it is very important to put a correct namespace if you do not put the correct name space then it will not be visible on the page for the namespace or your username so always remember when you create an image always create with namespace the name of the image and the version because version is something which which is here which is a Target now if you try to push it again since it is already there now if you try to push it again it will say the layer already exists so this layer already exists but whenever you change something you push it again a new changes will always be pushed to this particular image in the docker so that is how you push your image to Docker Hub how do you pull your image from Docker Hub into your local system the way to do is talk or pull your image name so let's try that docker image name and version it says pulling from code decode test me this is the Sha 256 digest and the state is the image is up to date from the docker Hub now since we have only pushed it a minute ago when we pull it it says that in your local this particular image is already updated in local weather you see your image so this is your image here now how do you create a container from an image so if you can see your image is created it is pushed to Docker Hub now you need to create a container can you see any container here no you cannot see a container here so how do you create a container the command for that is Docker run minus I T minus D or image name so let's try that Docker run minus I.T what does minus it say is minus i t is a combination of two commands that is interactive and TTY it basically tells Docker to keep the standard input attached to the terminal so open a terminal in the interactive mode that is the basic understanding of this minus i t command to Docker that is open it in a terminal keep it in an interactive manner that means all the inputs and outputs will be given into terminal only next is minus D when you do minus D your logs will not be seen here in the console it will be running in the background I don't want to do that so I'm not going to do it and your imagining but before that I want my container to have a perfect name so minus minus name what will be my container name I can say it as May container and your image name so now if you can see my container is up and running and the name of the container should be my container so if you can see here this is the make container that is the container that has been created as of now and these are the logs coming here that this is how you create a container now how do you list all the containers which are running so the way to do it is Docker PS or Docker PS minus a to show all the running and the exited containers so let's see first Docker p is I've closed the container as of now I'm going to clear the screen and see Docker PS this is going to list all the running containers currently you can see there is no running container all the containers are exited so let's try running one of the container and it says it is running so how many containers are running one so when I do Docker dot Docker PS you can see the initially it was empty but as soon as I run my SQL container it is also running with the container ID this is your image from where it is running you can see that here and the name is SQL container this is only the one which is running in the green sign this gray is suspended or stopped one this green is up and running one now with Docker PS space minus a you can see all those containers so this is May container this is a SQL container this is demo container so all the containers that you can see here you can see here also so this is your command line commands for showing all the containers which are exited as well as which is running while this is the place where you see the containers in a GUI format in much better way where green says it is running gray says it is stopped or exited so that's how you can work with both the command line and the GUI whichever suits you better so these were two commands to list all the containers either running with only Docker PS and all those which are running or exited with PS minus it now this one scenario based question for you suppose you have three containers running and out of these three you wish to access one of them then how do you enter into a running container so suppose I had many containers running here now suppose I want to get an access to one of the container how do you enter that container so here you can do is you get into this and add to the terminal and directly get into the Container it is easy in Docker desktop but it is not that easy when it comes to the command line so let's clear it and let's see how to enter into a SQL container so the command is Docker execute in in the terminal itself give the container ID and Bash then you will be able to enter that SQL container through your terminal only so let's try this Docker execute in open a term open a terminal in the interactive mode give the container ID so I want to enter into my SQL container so I'm going to copy it and paste it here this is the SQL container I have and open it in bash now here I am I have entered into my container this was my MySQL container and I'm able to enter into this now what next I can do being in an SQL container I can login into MySQL container so the command for that is MySQL space minus username username will be admin and minus password and password for me is root and it says welcome to SQL monitor now I want to show you databases these are all the databases I have created in my container which is up and running as of now for me so this was SQL continue which is currently running for me and these are the only databases into this particular container so that's how you enter into any container and add some commands to it now you want to see the logs for that the command is Docker space logo container ID let me just close this terminal and let's again see the color let's open the normal command prompt and see the logs for a container so Docker logs your container ID from where can I get the container ID for this from here enter now you can see all the logs of this particular container here in your terminal or command prompt itself so this is how you can check your logs now how to start stop and kill a container so I have a container already started which is an SQL container so how to stop it this is currently it is green the way to stop it is Docker stop your container ID token stop what is my container ID this now can you see this green is converted to Gray and it is stopped now how do you start this Docker starter simple Docker start your container ID I can see the container is now started sorry when Docker stop was there my SQL container was running it was stopped and hence everything turned into gray now when you start again this is up and running with the green similarly you can kill the container you can remove the container which is already stopped using the kill and RM command now how do you delete an image from the local system the way to do that is first let's see all the local images stored so that is Docker images so let's see all the docker images we have in the system these many images you have in your system where else you can see all these images you can also see all these in the docker desktop now how do you delete an image from the local system suppose I want to delete my test image that I have created here so how to delete it currently you can see code decode test May to delete it you can use a command Docker remove image and your image ID and what is your image ID from here you can copy your image ID and after that you will not be able to see this image here so let's see Docker remove image and your image ID so it says there is a problem there is a problem to delete because image is referenced in multiple repositories now this test image is getting being used in containers and since containers are here it is getting referenced in the make container it cannot remove it so let's try deleting this container then we will try to delete the image what is the way to delete a container to Docker RM your container ID which container ID I want to remove this may container ID so I've copied the container ID and let's first delete the container Docker remove your container ID great so can you see your container May container is now deleted from here now in the images can you still see the test Mason image let's try to remove it now what's our Command Docker remove image with image ID so docker remove image with Docker ID it says it must be forced it must be being used in either some volumes or somewhere we don't know so let's try to remove it forcefully now so this is where our test May image is there let's try to remove it forcefully and untagged and can you see it is removed from here there is no more test me image still present here so that is how you can remove your images from here but the best way which I always prefer is using it with a GUI it's comparatively much more easy so I can again show that to you deleting an image and container from here we can create an image test image and test my image again this image is created with test me this image is again created with test me and the way to delete from Docker is using this delete it says it is being used in a container try deleting it so it's being used here so let's delete this container first then you will be able to easily delete this so things are much more easy with GUI but if you want to have some commands you can always use it from the command line the last thing how to know the details on list of all the networks used in a cluster the way to do that is Docker Network so let me clear it Docker Network LS so these are all the networks available in your system for connecting with the containers there are many many more commands which are used in Docker if you want to know more about any of the command just let me know in the comment section I'll create more such command videos for you but whenever as in an interview these commands are more than enough when you tell how you have dockerized your application so just to summarize these two are for Docker version that you've installed on your system then how to build an image how to push an image how to pull an image from Docker Hub how to run a container how to create a container by running an image how to see all the list of containers which are up and running and this is a to how to see all the containers which are exited as well as running so these are total containers in your system then how to get into a particular container the ways to execute this command the docker ID execute ID container ID and batch so this is how you can get inside the container in your command prompt how to see the logs of a container how to start stop kill remove a container how to remove an image how to list all the images and how to know all the details of network here so these are all the common commands which we use when when you need to dockerize any spring notification that was all about the docker commands in the next video we'll be meeting with more such commands if you let me know in the comment section thank you
Info
Channel: Code Decode
Views: 10,764
Rating: undefined out of 5
Keywords: docker interview questions, docker interview questions and answers, code decode, docker interview questions and answers for experienced, docker interview questions for experienced professionals, docker interview questions for experienced, docker tutorial for beginners, docker tutorial code decode, docker code decode, docker interview questions code decode, docker interview questions for devops, code decode docker, docker commands, docker commands for java developers
Id: fwtVq7yEkzo
Channel Id: undefined
Length: 16min 16sec (976 seconds)
Published: Thu Jul 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.