Complete Docker course in 30 mins | Docker Tutorial for Beginners 2024

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Docker a very popular conization platform that is used to deploy almost every model application these days so in this video I will be teaching you Docker from scratch along with a Hands-On demo where we will be koniz a node GS application so make sure you watch this video till the end let's start welcome to complete Docker course for beginners in this course you will learn what is Docker and why is it so popular understanding the problem that Docker is actually solving next we learn the concept of containerization to understand the difference between containers and virtual machines moving on we go deep in the docker architecture to understand how Docker actually works what is Docker client what is Docker demon and lot more and to to make sure that you understand things more properly we will be doing a Hands-On demo where we create and containerize our first application to deploy it as a Docker container doing so we will learn important Docker commands that you will be using everyday as a devops engineer and lastly we will understand how Docker is used in real life deployment because learning Docker is not enough you need to understand where is Docker used in real life deployments so make sure you watch this video till the end and to make things easy for you I have notes created for this Docker course if you want me to share this notes with you comment down Docker course in the comment section and I will share this notes with you with that being said make sure you like this video And subscribe to Cloud sham for more s devops courses now let's start with our Docker course okay now before we look at the definition to learn what is Docker I want you to understand the process of how an application was deployed before Docker came into existence so before Docker the developer used to write application code in their preferred language which could be python JavaScript nodejs anything along with the code we also require necessary dependencies and libraries for the application to work so we could test this application locally if it works fine we then create the deployment artifacts also known as builds which could be deployed on production server but for this application to run on production machine we need to have the same dependencies same libraries with the same version or else it will work on your local machine but not on production and this was very common before Docker was introduced whereas after Docker the developer used to write the application code then create a Docker file which would have instructions of how you want your application to be from this Docker file we used to create an image and then this image was deployed as a container on production server using this approach the application would run fine in any environment without any issues so this is the problem that Docker has solved using Docker containers you can deploy your application in all environments without having any dependencies or Library issues now that you have general idea of why Docker is used and what problem it's solving let's look at the definition of what is Docker and according to the official documentation Docker is a containerization platform for packaging deploying and running applications as containers so what is containerization if if you have worked on virtualization tools like virtual box and VMware containerization is a lightweight form of virtualization that allows you to encapsulate an application and its dependencies into a self-contained unit called as container so inside this container you will have the code along with other things like runtime libraries environment configurations it will also have its own operating system and this is why it is called as lightweight form of virtualization so Docker applications run in containers that can be used on any system any operating system any environment a developers laptop system on premise or in cloud and it will run the same so here is an example of how containerization works and how containers are created we have an operating system on which we install Docker or any container runtime and using that container runtime we create three different containers here is a container which is running a Java application on red hat operating system second container is running engine X web server on uben 2 operating system and the third container is running PHP with mySQL on Windows operating system so on the same machine we have three different containers having three different operating system and this is what containerization is which is a lightweight form of virtualization to understand this more better let's look at the architecture of how virtual machines are created and how containers are created to create virtual machines we require a hypervisor technology like VMware or virtual box using that we can create different operating systems like ubben 2 red hat Khali whatever you want in your base operating system so here's an example you can see in this picture we have Oracle virtual box where we are creating three different operating systems inside it when we create these operating system we need to Define how much CPU and RAM should be given to each operating system so we are dividing Hardware requirements to every operating system that we have in this virtual box here whereas in the case of containers we don't do that we have a container engine and we only separate containers on the basis of what applications are we running on it this is why it is called as lightweight virtualization because we are not assigning CPU or CPU or memory requirements to each of these containers and due to this containers are lightweight and more efficient compared to Virtual machines as they are lightweight containers are very quick to start whereas virtual machines are slower to start containers are separated by processes whereas virtual machines are full OS isolation containers are highly portable whereas virtual machines has compatibility concerns resource overhead is less containers will use less CPU and memory compared to Virtual machines and containers have lighter isolation as well if you want to learn more about difference between containers and M AWS has explained how containers are different from virtual machines due to all the differences here are different advantages of containerization over virualization containerization is consistent test environment for development and QA crossplatform isolation ability to scale a lot more now to start using Docker you need to First install it and you can do that from the official documentation so you can install Docker based on your operating system you have Docker desktop for Mac for Windows for Linux I'm using a to Linux I can go ahead with installing Docker desktop on Linux all I need to do is to CH choose my platform then download the step package this is going to be similar for you if you're using Windows or Mac you need to install the exe file or run a command in command prompt make sure you go through the system requirements before you install it optionally I can also run this commands here but I'm installing the de package once I do that Docker will be installed in my machine and I can start working with Docker running Docker commands to prize my application to pause the video and come back after the installation is done after you install Docker and Docker desktop from the official website you can open up Docker desktop on your laptop this is Docker desktop a graphical user interface where you can see all your images containers and volumes running in your local machine optionally you can also use Docker CLI which is a command line tool and that lets you run that lets you manage Docker containers using commands to confirm you can simply run Docker D- version command this is this will let you Docker is installed and the version is 25.0.2 this is Docker desktop the graphical user interface this is Docker CLI command line interface now in this Docker desktop you can see the containers right now we don't have any containers but I can con I can create and we will be able to see it here similarly you can see the images volumes Dev environments and Docker Scout Docker Scout is a feature by Docker that lets you scan your images for any security issues and I have explained Docker Scout along with other features like Docker and it in my previous video you can check it out here now once we have Docker installed in our machine we are ready to start with learning Docker handson and also to containerize our application we create and containerize our application but before we do that being a good devops engineer you should be understanding what does Docker consist of how Docker actually works so let's go deep in understanding the docker architecture Docker consists of three important things Cent Docker host and registry inside Docker host we have a Docker demon which is a background process responsible for managing Docker objects like Docker containers Docker images and then you have Docker client a a client is a tool that could be graphical user interface or CLI command line interface that is used by the users to interact with the docker demon through API calls so you run the commands like Docker build Docker pull through the client which in return will create containers or create images using Docker demon processor next once you have your images created you can also store it on registry which is dockerhub the default registry Registries let you create repositories which are of two types public repository private repository same as GitHub and we use it to store and distribute Docker images so Registries let you version distribute and share images across different platforms and that is explained here in the text so if you want me to share this notes with you commment Docker Co and in the comment section moving on let's do a Hands-On project where we containerize a nodejs application and deploy it as Docker container also we will be pushing that Docker image on dockerhub so you will learn how to containerize an application how to push the image from your local machine to dockerhub uh similarly you can also do it to other repositories like ECR for this Docker project we will be creating a nodejs application that is a Todo application where we can create list of items and also check them once we do it we can also delete them if we want to so we so we will be containerizing this application the code for this is present on my GitHub repo and I will put the link in the description so go ahead and clone this code to start with containerizing this application if you want to learn how to containerize a python application you can check out this video where I've explained how you can containerize a python application using Docker commands so if you want to learn about python you can check it here in this demo we are containerizing a node GS application and the code is here so I'm going to go ahead with cloning this code in my local machine so let's go to projects folder and inside this I'm going to run the command get clone which will get all the code inside my local machine once the code is there I'm going to open that that repository which is learn Docker and let's open this in my vs code so here is the code you can go ahead and go through it this code uh is written in JavaScript this is a nodejs application which is going to create a too app Todo app uh which also uses postest database to insert data into now to run this application locally you need to run some commands and I'm going to show you how to run it locally then how to containerize it and run it as a Docker [Music] container in this code we have list of dependencies present inside package.json that we need to install in order to run this application if we don't have have this installed it will not run so I'm going to open up my terminal to run a node GS application we use the command npm start but before we start it it will give an error saying module not found so we need to install all these dependencies or else it will not work so to install all the dependencies I'm going to run the command npm install and this will go ahead and install all the dependencies creating a folder named as node modules here which will make sure that the application runs having all the dependencies installed so now if I run npm start command you can see it gave us the log output saying the application is running on Port 3,000 so let's go to our browser and open port 3000 so I'm going to say Local Host and 3,000 and this is our too application where we can create stuff and also delete it this is what we want to containerize so rather than running it locally on our machine like we are doing it now we want it to run it as a Docker container there so how can we do that to do that we need to follow the docker workflow what is a Docker workflow so you want toize an application you need to follow this stalker workflow where you first write the code so the developer is going to write the code for the application we already have the code present so we are skipping this part now second is to create a Docker file so we need to create a Docker file which is a file that includes set of instructions on how you want your Docker image to be once you have the docker file you can run the command to create a Docker image a Docker image is kind of a snapshot or a screenshot of your application which you can share uh which you can share using dockerhub or which you can directly run as a Docker container so out of this code we need to First create Docker file through using which we can create Docker image and then we can share this image or run it as a Docker container so let's start with creating a Docker file now so inside my vs code I'm going to create a new file and name it as Docker file make sure to use the same naming Convention of naming format and you can see there's a Docker symbol here which means this is this is a Docker file one more thing to note if you're trying to run this npm command or try to run this node application you need to have node installed in your machine I already have node installed so if I run node DV command you can see node node and you can install node for your operating system I have it already installed if you're trying to run it locally make sure you have it installed in your machine and only then you can run this nodejs application so now let's start with writing our Docker file inside Docker file we will have set of instructions on how we want our container to be so I'm going to quickly create a Docker file for you if you want me to explain if if you want me to create an in-depth video explaining all the different Docker file instructions let me know in the comment section and I will create a video where I go deep down understanding all the different instructions to create a Docker file so what are different instructions that we can use to create a Docker file if I go to the official documentation by Docker and search for Docker file instructions you can see to create a Docker file you have to use all these different instructions like from uh label environment entry point and these are used for different use cases we use the from instructions to set the base image on which our container is going to be created then we use the EnV instruction to set the environment variable we use copy instructions to copy files or folders from one one place to another similarly we use CMD argument add and all that as I said if you want me to create an in-depth video on all these different instructions let me know in the comment section and I can create a practical video explaining each of these instructions step by step with that being said now let's start with creating a Docker file for our application so we can containerize it so the first thing is going to be setting a base image so I'm going to say from so as this is a node application I'm going to use the base image as node uh and you can find all the images on dockerhub so if you go to dockerhub which is a public registry where you can file all the different images you can search for node so I'm going to search for node here and you see node is here which is the official Docker image these are the official images maintained by node itself or the company itself so I can click on this and now if I want to use this I can simply say Docker pull node which will get this image in my local machine but I'm going to create Docker file so I want to use an image or the base image from all these different versions here so I can choose to use Docker 21 hyphen Alpine or anything here let's try to use something uh let's say 21 hyphen Alpine here so I'm going to save from node colon 21 hon Alpine so I'm saying I want to create my container based on this particular image so you can see the from instruction is used to set the base image for subsequent instructions once we have the base image set I'm going to set the working directory which is the folder inside the container where I want to start working from so you can see work directory is setting the working directory for any subsequent add copy command that follow in the docker file so once I set this working directory all the next instructions will be running inside this particular folder which I'm going to set as/ user slsrc SLA next I'm going to copy my package.json which has all the dependencies from my local machine inside my container so I'll say copy package dot along with uh package I also want to copy the package lock so I'll say package star which means every file starting with package should be copied from here into the Container so packet star. Json from here inside user slsrc slapp folder now once I have this I'm going to run the command to install all the dependencies which was npm install command if you see we run the npm install command uh to install all the dependencies present inside package.json so I'm going to say run instruction which is the instruction to run a command so using run you can execute any command so I'm saying run npm install this will install all the dependencies to make sure our application uh to make sure our application is ready to run once I have that I'm going to copy everything from here to my container using the same copy command so copy Dot from dot dot means everything all the files and the folders from here inside the/ user slsrc slapp folder once I do this I am now ready to run my application but before I do that let's expose the port uh we run our application on local host on the port 3,000 so I'm going to expose the same application using 3,000 Port here once I do that I'm going to execute or run my node application using CMD so I'll say npm start so npm comma start so this is our Docker file which has different instructions first we are setting the base image which is node Alpine node 21 Alpine then we are setting the working directory on which folder do we want need to start working next we are going to copy our package.json files and we then run the command to install the dependency we copy everything from here inside the container expose Port 3,000 and then command to start our application so we have our Docker file ready now we are going to run the command to create an image out of this Docker file so if you follow the docker workflow after we have the code we now have the docker file so we are going to run the commands to create a Docker image from this Docker file so so to create an image out of the docker file we are going to use the command which is Docker build if you want to see all the different commands you can just type Docker and you will get the list of commands build an image from a Docker file so the build command is used to create an image from a Docker file we have a Docker file ready so I'm going to say Docker so I'm going to say Docker build hyphen T stands for tag which means you can give the name to your image so I'm going to say my Todo app so my too app and then I'm going to say use the docker image present inside this folder which is here so I'm saying Docker build hyphen T create an image from a Docker file present inside this folder having the name my Todo app once I run this Docker will start creating the image layer by layer so you can see it's now in building stage and this is the first layer which is the from instruction then it will go and execute the next layers to create a Docker image so very soon we will have an image named as my to do app which we can share on dockerhub or also run it as a container so you can see it is installing the packages here okay Docker build command has executed successfully let's run the docker images command this command is to show you the list of images you have in your local machine so when I run Docker images I will be able to see that I do I have a image created named as my Todo app which was created 14 seconds ago you can also see this in your uh Docker desktop which is the graphical user interface so now I have a to-do app which is created and the status is unused it was created less than a minute ago the size is this so now I can go ahead and push this to my Docker Hub or I can also run it as a Docker container before I push it to docker up let's test out if the container if the image is doing exactly what we wanted so when I run it I should be able to see the to-do application uh on my browser so to run an image as a Docker container we need to run the command Docker run and we can pass in some arguments like hyphen it to use the interactive shell hyphen D to run it as a detach mode in the background and hyphen P to attach ports or map the ports so I'm going to say run this application as a Docker container running on Port 3,000 in my local machine map to the port 3,000 on the docker container and with this I'm going to now put the image ID or the image name so that it can run it as a Docker container so I'm going to say the name of the image which is my Todo app so I'll say my Todo app once I do this you can see the it is going to run it it is going to run as a container so now once I press enter I get this random number and inside my ER desktop you will be able to see that a container is running with the name happy night angle you can also check that inside your terminal by running Docker PS command the docker PS will give you all the existing containers which are running so this container is running on Port 3,000 as you can see here on using TCP uh you can also see it here so if I open up my local L 3,000 I should be able to see a too application here which is running as a Docker container so this is how you can containerize your application you need to First create a Docker file using that Docker file you build an image and using that image you run a container so now we have learned the steps on how Docker books how do you containerize your application I want you to try this project the link for the repository is going to be in the description make sure you try this out to understand Docker properly optionally if you don't want to create this Docker file or if you don't know how to create a Docker file you can use the docker in it command which is the new command by Docker that will create Docker file compose file do Docker ignore file all automatically for you once you run the docker init command if you want to see how it works make sure to check out the video in this I've explained how Docker init can be used to automatically create Docker files for you uh and you can also use this documentation by Docker where we have used the same application and use Docker in it to create Docker files Docker compose file and run it using Docker compose here so this was our application I hope you try it out the link is going to be in the description for the repository make sure to try this out and share it with share it with your friends or connections on LinkedIn so now to understand how Docker is used in real life deployments we first test our application locally we first create an image and test it locally if it works fine then we push public Registries like dockerhub or private Registries like ECR as well so let me show you how you can push this image on Docker Hub similar same way you can also push your Docker images to ECR as well which is a elastic container registry which lets you store Docker images on AWS Cloud now to push this image from your local machine to dockerhub you first need to have a dockerhub account so to cre you need to go ahead and create dockerhub account if you don't have already I have my dockerhub account so I'm going to go and sign into it so this is my dockerhub account and you can see I've already pushed many of my Docker images this images are for my previous devops projects uploaded on YouTube this is the microservices projects images and this is the project from the cloud native monitoring application this is Netflix Dev secops project pulled by 700 people so you can uh push your images on dockerhub and people can pull it as well I'm going to push this image and I want you to pull it and see if you can run that image in your machine by running this particular command which is Docker run hyphen it so let's go ahead and push this image to push an image I'm going to create a repository repositories are of two type public repository and private repositories I'm going to make this public so that everyone on the internet can push so that everyone on the internet can pull that image and try to run it locally on their machine so let's name this as my to-do app and I'm going to say uh short description image for Docker project and I'm I'm going to click on create once I have this created I can go ahead with pushing my image from my local machine to my Docker Hub here you can see this is the command to do it so we need to have the image with the name as N1 or else Docker will not recognize where to push it so before we do that we also need to Docker login or connect our terminal with the docker Hub so I can say do Docker login and it is asking me for my username and then my password so I'm going to put my username which is this optionally you can also connect to your Docker hub using your Docker desktop you can see it says not connected to the hub and you can connect to it by clicking on sign in and then putting your email ID I'm showing so let's connect to our Docker hub using the docker desktop I'm going to click on sign in option which will open up once I do that it's going to verify credential and very soon our Docker Hub will be connected you can see now we are connected to our repository so let me show you the images we have right now in our in our machine we have a Docker image named as my too app I want to push this image from my local machine to my dockerhub repository to do that first we are going to change the name of the image from my too app to username slm my too app or else Docker will consider this as an official image and it will not be able to push so I'm going to First tag it saying togger tag my Todo app to use username slm my too app you can also check that in the off you can also check that here I need to tag it first and then I can push it to my Docker Hub here so let's do that once I press enter it is now changed the name has been changed so when I Docker images I have a new image with the name this and to push this I'm now going to Simply say Docker push and this is now going to push from my local machine to my Docker Hub repository which is here only when my Docker login has succeeded so we have connected to uh a Docker hub from here and you will see very soon the image is going to be pushed from my local machine to my Docker Hub this is something which we do in production although this all this process is automated using cicd pipeline the creation of Docker image the creation of container and the deployment of containers on kubernetes is all automated using cicd pipeline and if you want to learn how to create that you can check out my previous videos this is how we do it in the production and I hope now you have clear idea of how you can create a container how you can create image and so on so now you can see in my to-do app repository I have an image which is pushed a minute ago and now you can go ahead with cloning this or pulling this image and it will work fine for you so to pull the image all you need to do is to run the command Docker pull and the image name so Docker pull the image name which is which is this so once you run this command it will pull up an image and you can start running it using Docker run command so we have learned different commands like Docker run Docker pull Docker images Docker PS to check existing C containers if I want to stop this container I'm going to say Docker stop and the container ID which is this uh and I can also delete this container if I want to by running Docker RM command when I stop it you will not be able to see in the docker PS command but you can see it in the docker ps- a command which will show you all the stopped containers to delete this I'm going to say Docker RM and then the container ID which is this once I do that Docker you you will not be able to see the container anymore similarly if you want to delete any images you can use the docker RMI command so Docker RMI and the image ID will delete the image and you can see you can also use hyphen f to force delete Force forcefully delete an image and that's how you can delete it all the commands are present inside this notes here so the commands to pull build image and everything is present here I also have a LinkedIn post created where all the different commands on Docker is presented very carefully uh very nicely you can check out this post if you want me to share it let me know in the comment section and these are the commands to build an image from a Docker file to list all image to pull an image uh to remove a local image and so on so so this is the end of our Docker complete course I hope this video was informative and I've taught you everything about Docker along with the Hands-On project if you have any questions any doubt do let me know in the comment section and make sure to subscribe Cloud Chan thank you and have a good day
Info
Channel: Cloud Champ
Views: 36,989
Rating: undefined out of 5
Keywords: docker tutorial, docker tutorial for beginners, docker, what is docker, why docker, docker course, docker full course, docker full tutorial, docker course for beginners, docker course 2024, docker complete tutorial, docker complete, docker tutorial for devops, docker course full, learn docker from scratch, docker from scratch, introduction to docker, docker crash course, devops, what is docker and how it works, learn docker, docker 2024, getting started with docker, kubernetes
Id: q5S14cfOWfE
Channel Id: undefined
Length: 30min 13sec (1813 seconds)
Published: Mon Mar 18 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.