A practical guide on Docker with projects | Docker Course

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey there everyone atesh here back again with another video and in this video we're talking about Docker and not just talking about them we are going in depth of Docker end to end all that you should be learning about Docker I'm 100 sure that you have watched a lot of Docker videos and you're always confused like why so much of the content around the docker is it such a big subject is it such a small subject should I use it in Daily production life or what is even the first place the docker why there is so much of buzzword around it now the goal of this video is really simple I have previously explained as well as recorded a few videos on Docker but now the docker in 2022 and moving forward 2023 is much more of a simpler subject compared to when it was introduced when it was introduced there were so much issues in installation there's so much issues in walking through the guide of Docker as well but now it is one of the simplest thing that you can install and just forget about things the way how how you write your code is also much more simpler as compared to the previous ones nowadays nobody installs mongodb postgres or MySQL on their system a lot of developers prefer to do them with the docker way and that means no installation and always a reliability when your application moves from your local system to the production it faces the same environment that means same bugs and the same reliability also comes into the picture now I have adopted this new approach of explaining the docker so that everybody can understand this now I am sure in a lot of videos you have seen that there are a lot of theories before getting started into the docker and then they walk through what is container what is virtual machine and all of that and I recently find out in one of the class that I took that if you go and take a different approach on explaining the docker the results are fantastic the different approaches don't explain them what the Dockers show them what the docker is and we're gonna directly jump into the part where we actually practically do all the docker stuff and in the meantime in between I explain you the concept of containers and spaces and volumes and images and all of that that is far more of an easier way to understand the docker and yes I assure you after watching this video you will have no problem in understanding the docker not only that once we are done with the Practical part of the stalker then we'll move into the project part of the docker you will learn that how you can actually dockerize or containerize your application built in Python and JavaScript and lot more but the good part about this course is in the initial section and a long big initial section you don't have to worry about any programming language I understand some of you come from Ruby on Rails some come some of you come from PHP some of you come from the world of JavaScript and Java and you really don't want to use any programming language to understand Docker I hear you I understand you absolutely and in this initial section we will not be writing any single code yet you will be mastering the docker I and that is the best part about this covers now there are enough of repositories and images available in the docker that you don't even have to touch any programming language yet you will be understanding not just containers but multi-container deployment as well yes we are going to go through all this right one thing that is absolutely amazing about this series is we're going to be jumping into the documentation I know I know some of you absolutely hate that but the way how you should learn things is via the documentation and that's where I'll be helping you out in looking into the things that how you can look for API references of Docker and learn about more commands how long you're gonna stay with the tutorial Hill you need to learn things on your own and that's where documentation helps you so welcome on board into this amazing journey of Docker and together we're gonna have a lot of fun along with from the installation to moving things into the production I hope you're all excited let's go ahead and get started with the docker all right the first section we are going to go ahead and get started with the installation because that is most important part now I understand that in a lot of time in the old days you have struggled with the installation but that is not the case we are moving towards 2023 the docker installation is one of the most simplest one regardless if you're on Windows or Mac or wherever you are all you need is the most updated operating system as long as your operating system is up to date that's all you need now let me walk you through that how we can go ahead and install it's really the super easy installation this video was made possible because of agent T agent.com offers so many of the product one such product is web scraping no code web automation now this is a breakthrough and a game changing stuff a lot of mobile apps as well as web apps are offering out of the box their services and are earning so much through the advertisement Network what they are compared to what they are paying to agent.com I'll talk more about them in a minute so this is the place where you go on simply to the docker and this is where it says it says Hey I want to download it for Intel shape or wherever now the easiest way if you are on the Apple chip you can just click on and download Docker desktop if you're on the Windows just click up here it will download an exe which is super easy to work on with it's just an installer execution next next I agree just okay that's all it takes it's really simple for Linux as well yes of course it involves commands but if you are a Linux user this shouldn't be a big deal now let me walk you through with a couple of more stuff about the docker so if I go ahead and simply go for the docker uh docker.com so let me go ahead and copy this and paste it up here onto the docker.com now notice here couple of things there are now products and don't get afraid about seeing the pricing as well you don't have to do anything it's just for the personal so we don't have to get that Docker desktop comes up here with unlimited public repositories for the five dollar you can have unlimited private repositories as well this is something for the companies you would like to containerize that app and I think five dollar is nothing compared to what Docker gives you Docker is a containerization tool but we'll not talk about it right now we'll talk about that later on right now let's go ahead and look for that now two things that are really important for us before we get started I assume that you have installed it so go ahead pause the video and go and download this yes click click next I agree and okay and just download that but let me walk you through with that in the docs.docker.com you'll find download and install there is a documentation guide for that as well let's first discuss about Mac and then we'll move on to Windows so if I click on this notice here I get an option of download with Intel chip or the Silicon chip Apple silicon chip that is totally fine and there is no such extra installation instruction you can go ahead and do that from the command line as well but I highly recommend to go and use the DMG files that comes around super easy drag and drop into your application and works out of the box even with the Apple silicon as well there is not too much of the things now in the previous days you need to install some virtualization virtualbox that is gone that is gone that doesn't exist anymore Docker comes with its own kind of a virtual environment virtualbox you can say and it works out of the box so that is the best part about it now moving on to the windows yes there was a trouble in the earlier days that it was so difficult to install it but now Windows is also friendly with the Linux and the docker desktop that comes up gives you everything that you need for the virtualization so you don't need to worry too much the only thing that you need to make sure that your hyper-v is enabled it's really simple just look for the hyper V turn it on that's all you need to worry about that so that is all what it says and it says hyper-v and containers window feature must be enabled that's it just toggle on the box that's all it says and same goes for the Linux as well Linux is much more friendlier obviously the concept entirely comes from the Linux of the namespaces and hence the docker so there are multiple ways of how you want to install this and again they give you all the option for Ubuntu Debian Fedora Ubuntu is the most common one uh if you want to have a genome terminal that's great otherwise it just first asks you to remove maybe there is a previous installation so that is why all the things otherwise just these two commands whatever the version you want to install for the docker that is it and you can just go ahead and install and launch that so tell you the official documentation is always the best guide wherever the updates happen that is where the installation happen now I have already installed the docker so I'm going to go ahead and fire up my Docker app here and it just takes a minute once it is installed and it fires it up it moves it up actually at the top of the desktop and here it says hey this is where the docker desktop is let me quit it so that we can run this again so this should be gone uh in a minute just waiting for it to go away it is going to stop everything from the docker and by the way I have actually cleaned up my Docker so let's just go ahead and fire it up one more time we're going to go ahead and say hey fire the docker app and as soon as it comes up notice here this is how it starts it gives you nice graphical interface both on Mac and windows and it just says hey I'll be up and running within a few minutes now one most important thing about the docker on the left hand side menu you can see that there are four key important tabs we can actually remove the dev environment because it's in beta we don't worry about that too much the only thing we are worried about is container images and volume so if in the GUI these three things are at the top that means these are the important ones if I understand them if I master them that's all it takes to understand the entirety of the docker isn't it let's go ahead and see them so right now if I go ahead and look for the container there is nothing I can see there are scrolling couple of icons redis nginx and postgres no idea what they are but they are somewhere here now coming up on to the images okay there is no images right now uh there could be images in my report remote repository I'll walk you through why that is there but right now in the local nothing and in the volumes there is absolutely nothing so right now we are starting absolutely for fresh okay let's go ahead and get rid of that so this was your brief talk about the installation and how and what position you're gonna find your Docker okay let's go ahead now in The Next Step we're going to talk a little bit about the images so that you first know the first building block of the docker is to understand and know about images let's move on to image before we move forward I would like to introduce you to agent T now agent T has a lot of products to offer and this portion of the video sponsored by them and I will walk you through that how actually you can create so many of the web and mobile apps just by using their apis out of the box let me show you a couple of things so agent D has a lot of products as you can see at the top scraping detection agent sentiment analysis machine learning a lot of them what is some something which excites me a lot is scraping and we have actually built a lot of products around this not a lot but yeah two three products on that now it gives you a lot of scraping agent I'll tell you something so once you actually do a sign up onto this this is how you get you get a dashboard and then you can simply go ahead and create a new agent once you create a new agent what you can do is install a Chrome extension of that and all of these services that they offer are actually available through the apis and that's where you can actually build out-of-the-box Services a lot of people are doing it and it gives you scraping agent for example some agents that they have samplely created is maybe you want to scrap the images which are lazily loading not just these images don't come up on just the load of the image eventually as you scroll they come up and they have HTML table scraping Json data XML there's a lot of things CSV content scraping scrape your content put it into CSV directly put it into database and a whole lot of stuff now they have a pretty generous offering of what they can do and stuff but thing which is going to make you really interesting that you yes you actually have seen some of these implementation is through their browser API the moment you open their browser API you can see they have so many of the endpoint to actually do stuff for example you can convert any web page into PDF take screenshots get any HTML content of any URL extract some particular data and all of that and you can try them out using the postman and their Postman collection a lot of apps what they do is use these kinds of resources so now to share the fetch API you can use the browser agency apis put your API keys of course and then can mention any URL and it will convert that into PDF a lot of website do that and just put ads on their mobile apps or their websites and actually earn a lot through their advertisement Network that is being displayed so they offer the service to the user for free but earn like ridiculous onto the ad Network and you can do this all just with a click of that you can offer so many of these Services yes you can manually code them but if there is something which at a cheap rate can automate that and you earn a lot more through advice my network it's almost like a YouTube model that you provide the content for free but charge other people through different ways so yeah it's really great but not only that if you can come up here you can see many other products offered by them like change detection website change detection monitor alert software change tracking so there's a lot that they offer and they have a nice examples available and you can check out their pricing the pricing makes a lot of sense to people who are already into the business domain but most people will just say hey it's not free but yeah quality services you know they even offer that you can crawl the password protected website so obviously that comes up with a prize but I would say for corporate 29 per month is nothing for corporate and yes you can definitely go ahead and at least they offer a free trial try them out if you like them that's great if you don't like them that's also great but I'm pretty sure it's a little bit useful for you as well all right let's go ahead and move back to the topic now all right so in order to understand about the images just imagine the world if you remember that long there used to be a time when even these Ubuntu guys used to send us the disk images that hey if you want to try out our operating system here's a disk image the CDs in the world of DVDs the docker is inspired exactly by the same thing that your operating system and everything that you want to run comes in a disk and you want to run that disk now the docker images are exactly same let me walk you through onto the docker Hub so Docker Hub is a place where you want to check out for the images if you go up here I've already created an account and creating this account and logging in is really important if you really want to push your images to the docker hub for the later on use or maybe you want to push these images to some private repository something like AWS Amazon web services this account is required there also so creating an account on here is super important now you won't be seeing anything up here and these are part of some of the projects that we are going to use later on right now this is all what we have so here notice there is a button which says explore you click on explore and you see few of the common images which has been used for the daily life or maybe for the tutorial purpose and whatnot so notice here there are a lot of Docker images and all these things going on what I will do is I'll just click on the docker hobby here again and I'll just click on one more time for the repositories so these are my repositories yours might be empty what you see on the docker explore is the repository contributed by a lot of companies as well as developers like you and me what are the resource they wanted to give to the community now notice here the first one is Alpine so obviously these are suggested images and there are a lot of recently updated as well notice here nginx which is a server we'll talk about them in some another video which is a good popular one we have postgres we have redis we have we have memcache hello world there's there's a lot of them here now few of them are really insanely crazy popular one for example let me walk in through this busy box look at the downloads here can you imagine 1 billion downloads that is crazy look look at this other one the python one has one billion downloads and there is also Ruby quite popular one 500 million downloads so some of them are really really popular one BusyBox is one such uh image which has been used it's almost like a Linux so whenever we used to teach these Docker Concepts we just wanted to have a Linux so that we can teach the people the power that hey you can actually run a Linux just like in the virtualbox in the docker world and every tutorial has actually used as including me but I realized over the time this is not the best way and although I do have a series which uses BusyBox I realize there could be a better approach of having this so notice here there is even the Ubuntu over everybody's favorite so in the world of Ubuntu I can see that I can just run this command Docker pull we'll talk about that in a minute but I have a lot of tags tags basically means which version you want to download so there are a lot of versions obviously from Ubuntu we have seen a lot of evolution of Ubuntu all these things you can find up here so there's a lot of tags going on if I go on to the overview it says hey this is all the supported tags means you can download the version of Ubuntu from 16 to 14 to 22 wide variety of range how we can do that we're going to learn that later on in this video of course but this is all what it says now this is not a lot of people just look at for the tags and just read it until here which is not a good thing a lot of the juicy information about how to run the images and how it works and what are the important information comes at the little bit lower there where it says how the root file system was built and all of that right now Ubuntu is very easy in that part so we don't worry too much on that but we'll come back on to this one all right so far one concept is clear that images are nothing these are just like CDs and DVDs the disk images which has a lot of things in it and we can just run them now later on we're going to understand that hey how is it different from virtual machine and all of them right now is not a good time so we get the idea let's open this up and see that how much we have covered all right I understand that what are my images these are just like DVDs it could be of Ubuntu it could be a simple redis it could be a mongodb postgres whatever you are comfortable with all right but what are these containers that's an interesting one now whenever a CD comes to your home just like an Ubuntu do you remember that you could have actually gone ahead and installed that on your system yes now your system will be called as container yes exactly that is super simple just like CDs and DVDs need to be used in some computer and that computer could be yours your friends or anybody that system is now an Ubuntu system similarly we have a concept that now systems are so much powerful we've gone are the days when we used to have five MBS of ram now we have everything in gigabytes which is pretty powerful you can actually set Center up a Sandbox environment an environment which is simply just there which do not interact with outside environment just easily and it's just a standalone computer almost like that if using that images you boot it up and you load up all the things that is your container told you it's super simple to go ahead and work with that okay right now we understand majority about the images but we understand like 40 to 60 percent about what is container so we're going to go through and work with that all right so this is the time when we actually go ahead and work on with that so we're going to mess up with something which is really really popular and a little bit difficult to work on with that which is known as postgres a really popular database which is available and notice here the commands are almost simple Docker pull postgres Docker pull Ubuntu so this one command is going to do everything yes this actually does everything for us so let's go ahead and understand first that what this command is and how it works and then we're going to pull this image so we're going to go ahead and fire up a terminal now go ahead and switch up your videos into a larger resolution these videos are recorded in 4k so that you can watch everything in a clear crystal clear manner if you're going to be watching in 480 this will not be clear Docker output is really long and big and we need to see all of that output in one single shot directly up here so that is why I recommend to bump up your resolution okay all right so when you install the docker it actually gives you a couple of Docker commands not just the docker a couple of them if I hit my tab key after writing the docker notice here it says hey you can actually see Docker compose Docker Docker compose V1 credentials or desktop and whatnot and all of that the two most important for our purpose is Docker and darker compose not just for our purpose the entirety of the thing that you will be doing is going to be just these two commands and notice here if I want to check the version I have no idea how to do that I can run Dash V or maybe dash dash version no idea which one to actually pick up so I'm going to just go ahead and take a guess dash dash version it says hey this works but what if I could have just said hey I want to just go ahead and see you a dash V let's see what happens that it still gives you that what about v ah this time it failed so the reason why I'm showing you this is Docker actually comes with a lot of commands and you can see that here in the in the list here there are a lot of version options Dash V dash dash version which prints out the docker version but not only that it gives you commands like there's a config there is a node there is also a load login logout a lot of them now how we can learn and study more about them some of them obviously we're going to study in this particular video but how you can learn and explore more this is exactly known as the API references and API simply doesn't mean something which is on the web or gives you rest tape no it doesn't like work like that API is simply an interface and this is an interface of how Docker interact with my system or its own internal system so that is where the reference comes up so this is browse through the CLI and API reference of documentation if I click on this notice here there is API reference I'll click on this there is a Docker engine there's a Docker Hub API and registry API obviously we're going to go for just the docker engine and here are a lot of things going on so you can see but also if I look for the command line interface ah Docker CLI Docker compose Docker CLI which is Docker D we're not worried about that we'll just go for the docker CLI okay notice here there's a lot of commands going on in here for example if I want to just check out hey what this Docker login does let's just go ahead and see that or maybe there is a Docker version we just ran that command and we want to learn more about it I'll click on the docker version and says hey you can run Docker version and then can provide some options for example I can provide an option of formatting which formats my option and here are some of the docker version options that you can go through with that if I go ahead and format in this format it will give me output like that pretty interesting and let's go ahead and copy this command and try to move on to terminal and see that if this works if I go ahead and work on with that notice here it gives me a version of and I accidentally copied a little bit more so I'll just copy it copies actually everything not a good idea so I'll just copy this one there should be approved copy that and let's go ahead and try it one more time and I run this one at this time it gives me this version but if I go ahead and try the previous version Docker dash dash dash V then it says Hey Docker version all of this so you get the idea that if you really want to dive deep into some command maybe for some output API references is the best way of doing that now don't worry I'll not throughout the way we'll talk about the API versions of this one so but then so the docker documentation is equally important all right so let's go ahead and try to interact with that now I want to run ABA learn about one of the command which is darker pull let's see what it does so I'm going to go ahead and search for Docker pull thank goodness that they are in the alphabetical order so I'll just go for Docker pull now this is a command for pull an image or a repository from the registry too many jargon words all it is saying is hey just pull up an image it's mean like just place an order for the image and grab that image notice here we are just grabbing the image we are not running that image that means we are not installing it on a computer right now we're just gonna be pulling that image right now we are interested in pulling the image of Docker pull and simply postgres all right so I'm gonna just copy this command which says Docker pull postgres we'll move on to my terminal really big one clean all of this Ctrl L is always the shortcut to clean this up and I'm going to paste this up let's see what happens with that now it says I'm using a tag which is the latest which is the default tag okay new information that whenever you don't mention the tag it pulls the latest of the image but if the latest is not available you have to explicitly mention that tag now notice here it is I just asked him to download one image but it is downloading so many of them now this is where the core practice of the docker comes up the docker images are not build wire just hey here is the postcard software you take it no it doesn't work like that in the world of Docker Docker images are composed of a variety of layers and you just saw that the layers are available now these layers make the docker super super smart let's just say you have worked onto postgres and there are some other the things which you have changed but underline what is the operating system which is running it and yes all the docker images comes with a we cannot call it as a full-fledged operating system but some component which allows the software to run so those components are still same maybe majority of the postgres is also same just a few top of the things are changed so we don't need to change entirety of the things we just need to update a few things and if somebody who is already having this image he just need to change a little bit so that makes images more efficient so always remember Docker is not composed of just one image it is composed of a variety of layers that comes into the picture and helps you to get that all right so now we can see that the docker.io library postgres latest was downloaded and downloaded a newer image all right now what happens if I run this command again if I run this command again notice here what happens let's see there we go this was it this time it was super fast so we concluded that if the image is not present in our system it will go online and will pull that images now here is a side note now I am logged in into hub.docker.com but the images like postgres mango nginx these are public images so that you don't need to log in to download these images but if you're trying to download something which is private we obviously need to log in and I'll walk you through how login actually works no worries on right now so we have concluded that we don't need to download this image again but I want to see how that image looks like so there are a couple of ways how you can do it the first way is obviously going back into the documentation and we can see that there are something which is known as darker something related to image so I'm going to go ahead and say Docker image I should be actually able to see that ah there we go Docker image so let's go ahead and explore that so we have this Docker image and a lot of commands involved with that I'll just look for Docker image it says Docker image and command so there are a lot of commands you can use like for example to build to history import LS list images nice one this is something that we can use there's also to prune the images remove the unused images prune easy way remove okay so this is all we can do let's try and run this list of images this is a nice command so we're going to go ahead and say Docker image remember we didn't call images these are two different things we are just looking for Docker image and then we can go ahead and say LS and unjust Escape hit enter and I have an image which is postgres latest with the tag the image ID and then I have seven days to go the image size is 358 MB a little big but it's okay let's go ahead and see that in the visual aspect and I go on to images and I see the exact same information notice here the tag is exactly same 340f340f and we have the latest unused eight days ago it was created we have all these images we can run it from here as well I don't want to but we can and I click on that and we can actually go ahead and push it to her view details blah blah stuff I'm not interested much into that okay all right this is great so far and we can see that this is now is in my local and I told you that I can actually go ahead and log in click on the repositories and these are the repositories which are pushed by me so later on we'll learn that how we can push it and how you can also push it but if I check it since I'm logged in I can look into remote repository and I can list down that these are the most repository which I have pushed so you get the idea that these are nothing more than just pushing the images all right so next up is now we're going to see that how we can actually run these images before we run these images I'll walk you through with a couple of more commands and the simple commands that we're going to go through is Docker PS so let me go ahead and search for that and that is Docker PS now this is also an interesting command it has a lot of options Docker PS lot of options like for example I can give a dash dash all to show all the containers I can filter them format them God knows what there's so many examples of that it shows the both running and stop container by option Dash a everything is here everything in the documentation you might get frustrated but I'll still introduce you to the documentation because that is the way to learn all right let's move on to the terminal and we learn another command which is says Docker PS it lists all the containers right now there is no container and as I just a moment ago told you that images is like ordering a simple image from the Ubuntu company or maybe this time postgres company and we haven't installed this image on any computer the moment you install that on a computer that is your container that's exactly what we want to do now so now I don't know how to actually do this so let's go ahead and again yes documentation there is a nice and easy command which says Docker run now the docker run has a lot of options and the command actually goes really really big it has an option of Docker ad host and whatnot you can see this is the most used command so that is why so many options are given to you yes I can keep on scrolling but the easiest one that it says that hey you can run a Docker run dash dash name test then the dash it and the Debian we don't have Debian we have postgres but we can actually modify this command a little bit now one option I'm looking up for is what is this Dash it because it sounds interesting it might be really good let's go ahead and try to search for that Dash it and there we go should be here somewhere Dash it somewhere let me just go ahead and try this out okay do we have anything above nope all right so this is the dash it and here we go the dash it instructs Docker to allocate a sudo terminal connected to the container ah too much of this basically it says that hey I want to interact with this image so just give me a terminal so that I can get into this and have my terminal to interact with it yeah really most use command okay all right so based on this let's see that it is giving it is a lot of option dash dash name then test and then it can I skip all of them and can directly say Docker run devian let's try this out so let's go ahead and see that if I go ahead and say it directly like Docker run and the name which is postgres and again it is super important that you give the exact name as the name of your image in this case the name of the image if I can just get it the name of my image is postgres and since this is the latest image I don't have to say colon latest if this would be some specific version which we are going to get then I have to mention that version for example 3.2 whatever that version is you can grab this version and I have to mention now some people prefer to put something like a release release at the end whatever the tag is you have to specifically mention that some people like to say hey I want to use Alpine we'll talk about that but yes you have to go Alpine then you have to go ahead and use that all right right now in this case we know that colon latest is by default so I'm not gonna just write anything and I'll just hit enter now it says hey there's some problem the database is uninitialized and super user password is not specific hmm that means probably we are doing something wrong that this first image that we picked up for the demo is not working and this is exactly why I wanted to bring your attention now when you take an example like BusyBox Debian Ubuntu it works out of the box it just works and you feel so happy about it and you miss the most important part of learning about the docker let's go ahead and see that onto the docker Hub we're going to go on to the postgres and we're going to see that how this is actually working we scroll a little bit and it says how to use the image so we have a long command that says hey you have to use Docker run dash dash name some postgres this is just a name you can call it Superman hitesh whatever you like then you have to use Dash e option and have to provide postgres password my secret password then say Dash D and postgres all right so instead of walking you through again in the documentation I can brief you and summarize you what all these options are now whenever you start any kind of database which is like postgres MySQL they just don't work out of the box they have to be passed on some environment variable that hey I know I am the authorized guy I'm logging in with the default passwords default uh usernames whatever that is I just want to get in the images now couple of more options are here dash dash name that is super important we'll come back on to the later one right now whenever the container is created a name is given to it sometimes people don't like that name so they want to pass an argument and give their own specific name we'll skip this part of the command so we'll not just go with that and then on top of that we want to pass on an environment variable that hey this is the variable name and this is my value for that and Dash D is a detach mode that means whenever a container spins off it actually keeps your terminal busy if you really want to move that container into back of the scene that hey I want my terminal free then you provide this Dash D as a detached mode pretty simple yes it's not that complex so let's go ahead and see that if we are able to actually run this through this exact same command all right so I'm going to go ahead and copy this entirety of the command and I want to modify this it's not like I want to directly use this command I'll move on to terminal I'll paste this command but I want to see that what happens well I don't give couple of options for example this e Dash e is compulsory because that's exactly the warning it gave it to me but here in this case the name doesn't seem that important so let's go ahead and try this out by removing the name all right like also I want to see what happens when I don't give this Dash D what happens when it is not in the detach mode Let's go ahead and try this out so our Command is really simple we want to say Docker run instead of postgres now this additional information came in and again I told you dash e is just passing on some environment variables all right let's hit enter and now it says hey there's something happening it is better than the previous one and at the end it says database system is ready to accept connections so that is the movement of Pride that at least we were able to learn something from the documentation and study it out and we were able to spin off a postgres now I hope you can imagine the power you can fire up as many postgres as you want and your system will not take that much of the heat it used to take when you install multiple version of postgres it's cool all right now let's study this a little bit that what is happening okay a lot of things happening but my terminal seems to be busy can I run more commands here can I go ahead and say LS hit enter nope I cannot I cannot it just keeps on hitting now I would like to press Ctrl C so that it stops everything it says Hey database system is shut down interesting so as soon as I get away from the terminal it just shut Downs my entire container let's see what is happening from the visual perspective I go into the Container all right so there is a youthful habit something and this postgres latest so this is exited both of them are shut down all right this is looking good and if I click on this run show only running container there is nothing right now that means I was able to pull down postgres I was able to run it for a minute but it's gone now all right and notice here youthful habit uh there is also a weird name Zina or something don't like I'm not loving it let's go ahead and try to see that what was this Dash D option was giving us Dash D which says detach mode I hit the enter it returns me a long string uh but does nothing I can run my command the container is free the terminal is free I go back and look at the dashboard and see that all right a new container was spinned up okay it didn't use the previous one notice concluded that it doesn't use the existing container which is stored it creates or spins a new container every time when I run a Docker run this time it calls it as Lucid underscore LS and it's running and it's keep on running that means at least as of now I can assume that I was able to successfully run it great so far great now let's see that how can I stop this right right now I don't know the stop command so I'll just come here and stop this and yep it exited it exited all right now let's go ahead and see that if what we do is missing commands are being broken down again so I go ahead and say that hey I want to use dash dash name and I want to call this as my postgres dash one I highly recommend to use dashes instead of spaces spacious is not a good idea and especially in the command let's go ahead and hit uh enter here this time okay another and notice here this string is different than this string so I'm pretty sure you can vouch it that it spins a different container this time if I go on to the dashboard okay but this time the name is not lucid and Youthful it says my postgres the string is same 8 to e37 great and it's running it's running it's keep on running now I want to see that what kind of or what all containers the docker is running enough of stopping from the GUI like who uses GUI in the world of Docker I want to see what all is there so if you remember we re we learned about a command which says Docker PS and all right we can see that the container is running now this my name is spilling out to the next line so I hope you can adjust that and that is why I told you spin it up to the 4K so that you can see all of this nice and clean I do have a container ID I do have a postgres image and the command something it was created up here status and the port is also here interesting we'll talk about the port later on but right now let's just see we can also conclude one thing that this was a long string but this guy is giving me a really strong really short one just five or six seven ten ten keyword 10 letters out of the starting so how can I stop this now now stopping the container is really really easy it's not really that of a big deal let's see from the documentation I want to stop a container so there is a Docker stop all right let's go ahead and see this Docker stop and then it says hey you have to mention the container let's see is there an example Docker stop my container interesting so there are a couple of ways I can conclude from here that Docker stop and then I can mention my container now if I know the name of my container that's great but if I don't know the name of my container I can actually mention the container ID both are same and I'll just have to say 8 2 E3 now don't worry I'm not going to write entirety of the thing you can definitely go ahead and copy paste it but if you write just the fuse initial letters of it and as long as some another container is not confused with it then it will just stop the right one if it found an ambiguity that hey there are random chances that the both containers are having first four initial letters same then it will do nothing yes that's the grade so let's go ahead and hit enter and it says hey this is stopped and verifying it is also super easy for us that hey everything is exited let's try it one more time this time we're gonna run this again and this time we're gonna run it with and again notice here very carefully if I run this command again we're about to see an error let's see that it says hey you are running an error which name is already in used so either you have to remove it or reuse the name so we'll learn that how this can be done but yes I can actually go ahead and run this container again and yes there is a command I can just say hey Docker run and just run my postgres machine like that or I can just come to that here and I can run this again and I know that this is running my postgres1 and I can go ahead and stop this so I'm going to go ahead and say this time the name which is my postgres1 hit enter and obviously this is going to start that so there we go all right a lot of thing happened but notice in the image we have just image container we have spent many uh that's okay and the volumes uh there are a lot of volumes is being created we have zero idea why this has been created but it has been created so at least so far we have some confidence that how this can be done all right so this is good so far now I want to do something more let's go on to this one where the docker is and I can see there are a lot of images for example there is a 13.8 image as well so my next obvious step is going to be really simple that I want to try out the power of the docker I want to run a postgres which is absolutely latest and I also want to run a Docker which is any given ID or the tag in my case let's pick up 13.8 I want to run both of them and see what happens that would be the next step that we'll be taking up let's go ahead and check that out all right so the goal is really simple I want to spin up two machines one with postgres latest one with the postgres 13.8 rest of the stuff will remain exactly same for example the stuff which says hey you have to provide the default password so the default password is same because it's the same machine and we have to provide some name as well otherwise it would be confusing for myself to differentiate between which one is the latest machine and which one is the old one all right that's all what we need let's go ahead and work on with our terminal first before I go there I would like to see onto the dashboard that I have containers which are running this so I won't be using this name I'll walk you through that how you can flush out all the containers can reuse the containers that is something we are going to study later on right now this is all the information I know all right so we do have this command which we wrote which is really simple which says Docker run and I want to use different names for each one of them now the most important one is the first one which we are going to go ahead and call this one as simply postgres latest and I want to go ahead and use this so again the most important part is this this is the postgres when you don't provide any of the tag it uses the latest of the image so let's go ahead and at least finish the half portion of the task which is getting us a Docker image which is of the latest type all right this should be done by now and let's go ahead and again verify with the dashboard okay the postgres latest is available it is running seven second great fantastic now how can I go ahead and grab the docker which is a little bit later which is let's just say 13.8 you can feel free to pick any one of them I go ahead and work on with that and obviously I'll be saying a different name for this one I actually missed the final T of that but you get the idea and we're going to call this one as postgres old maybe you want to give it a postgres 13 whatever the name is it can be any name but I have to mention that colon 13.8 so whatever the tag name is you have to provide exactly the that for example if I go ahead and use the version 14-alpine I'll in a minute discuss what is the cell Pine and you're going to see this throughout and darker world you can go ahead and mention colon 14-alpine r14.5 Alpine or 14 Dash Bullseye whatever the version you want to go with that I am happy with 13.8 and I'll hit enter and what is going to happen this is the time where you should be expecting it is not finding not able to find that image on my local system so it's going to do something different it's going to go on to the internet we'll look up hey can I go ahead and download the docker version 13.8 will bring it to the my system and then we'll run it so what can we say we have concluded that this run command is actually composed of two different commands it can actually go ahead and pull some images from the internet and also can go ahead and just run this if the image exists and looks like there is something it says hey I'm not able to find 13.8 locally so I'm going to go ahead and move on to pulling the images from the online and sometimes it takes time depends on internet speed connectivity a lot of variables but as you can see again we can re-verify that the docker image always comes in layer and this image is downloaded as well as this is the ID just like here it gave me an ID it is also giving me an ID let's verify this with the docker dashboard and can see how many images we have we have two images both postgres one is 13.8 one is latest verifying that and we have container as well now this container we have two containers postgres old and postgres latest okay now there is something really interesting we should talk about here now this information is not given to you here the port section is totally empty but if I go on to the docker here I can see at the scrolling a little bit the docker has a specific port on which it runs right now there is no mention of it I'm pretty sure there is some so let's just crawl it little bit there should be some Port mentioned up here and looks like a little bit difficult to find all right so right now we don't have any of such information that where it is but we can see that this there should be some issues okay right now it's not giving but let's see what is happening let me open up the terminal and show you that we've already learned a command which says Docker PS and there you go now this is a little bit let me shrink this a little bit so that you can see all of this in one line This is super important to see all in one line there we go at least now you can see the ports Now the default Port of the postgres is 5432 and here also 5432 now this is 100 sure that if you run two services on single port they are going to get conflict this is not a rocket science everybody knows about this so yes we are running two different versions of postgres on one port that are obviously going to create issues so in the future we have to learn that how we can pass on one more parameter so that this port conflict can be avoided and we can learn something about Port mapping Concept in the early days I showed you that images is like DVDs and container is like running a virtual machine in your system almost like it's not a virtual machine it's very lightweight than a virtual machine and doesn't include an entirety of the kernel as well so the thing and important part is that whenever you run this machine which is a Sandbox environment inside your computer it needs to expose some Port so that outside your computer or your entire world can actually connect over through that Port that is what exactly the port opening or the port mapping says your main computer to this closed environment this 13.8 and this latest version both needs to have a port now we can we can be assure that this always is going to open up one port which is 5432 but this 5432 can interact with 5000 on my machine and this 5432 can interact with 4000 on my machine so all I have to do is just mention different ports and these two Services can be interacted with how cool is that all right so that is why I told you learning things on the go is far more easier in the world of Docker than just mentioning these uh presentations and all of that so this is super easy all right so now we need to learn that how can I stop this container we have learned that so far we can learn uh run stop that by using that click click now we want to do that we'll just say hey there are some options here like container and there are a lot of options here so obviously whenever we have these options we go up here and we see that hey I want to learn about the docker container so can you actually explain me a lot here it is so Docker container has a lot of things attach commit copy create execute export there's a lot of things if you want to learn about any one of them you can go ahead and learn that I want to learn about Docker container stop it says Docker container stop and give me a container and you can provide options as well like for example time T like that there's a lot of option but right now these are all related commands I don't need to study all that is saying that hey there's an option of dash dash T in case you want to know the time but all you have to say is Docker container stop and then provide me the container okay all right seems pretty easy let's go ahead and see that I will say hey Docker container stop and I'll give you the name so I had the name postgres latest and postgres old but I'll go with the container ID this time for one so let's go ahead and hit enter there we go it stopped and for the second one I would love to go for the name but first I'll say simply Docker LS and ah my bad Docker PS to actually see the container and by the way there is also one more command you can go ahead and say Docker container LS and it also gives you the list of all the containers that are running uh yeah that is confusing you can run Docker PS2 that also gives you the same but you can also run Docker container LS which also gives you the same I get you there but this is how the world works a lot of options to do the same thing now let's go ahead and solve the another one Docker container stop stop and we'll give the name this time the name is postgres latest so we're going to go ahead and say postgres latest without the T which I made a typo let's hit enter and there we go now in theory there should be no container which is up and running so let's go ahead and see Docker container LS there is no running container as of now if you remember in the documentation we learned about one more command which is Dash a which gives me the list of all the containers whether they are in running mode or not there we go so many containers are there and yes this is where the shipping container and all these things comes around pretty nice actually all right so this is good and here are a couple of things I would like to mention the first thing is a common argument that comes up is a Docker versus VM the VM is bloated it is very heavy it's almost no it is not almost it is running an entire operating system on top of an operating system that is your virtual machine is Docker is not like that Docker runs your application on top of the system it doesn't include the entire kernel that is the most diffic most important difference between the two the most important thing that you should always keep in mind is Docker is comprised of whatever the application you have enough of configuration and enough of the OS layer that can bare minimum run it it uses and interact with the host kernel that whenever it is required to do something for example there are some commands that you want to run for example some copy commands which runs actually on the host and moves things into the container that is where Docker interacts with the API of the host simply saying it interacts with the commands of the host that is how it works so this is is the most important and really simple and the speed the most important part of speed Docker is super fast the way how you are able to run these OS just like a breeze of a command and how fast this is working not at all likely remotely merely possible in the world of virtual machine for this long we would have just spinned off one machine that's it and we are spinning up machines and containers like anything this is the real power of this one all right now we want to run certain things as well and want to explore a little bit more of the database I will not remove anything the containers let them run we'll remove them later on we'll see some of the standard commands a hack from the stack Overflow that I found everybody found it from there and we'll see that how we can remove all the containers in fact let me first show you that because I want to show you the actual resource where it actually came from that so we're gonna just find out Docker stop all containers so there is a nice hack and we're going to say that stop we have already stopped so let's just go ahead and search for remove all containers remove all containers so there is a nice hack on the stack Overflow it actually pops up first there and then everybody started to just move it there there is a nice interactive guide here so you can just use a Docker system prune obviously we can or we can say Docker container prune this will remove all the stopped container all right we know that we can learn this from the simple commands as well on from the documentation we know that the docker container prune is there and we can see that it removes all the stop container but what's the fun in that we can actually go ahead what I want to show you something here is something this so a guy got from uh charmese credit so all he actually showed that you can actually use Docker remove and can pass an argument Docker PS and just get all of this and it will also remove that I don't recommend this but still a lot of people will show off you for the Powershell user and all of that right now let's try what is this another command that we just saw here Docker container prune let's see what happens with that let's go ahead and say Docker container prune let me move that on the top prune let's hit enter and says hey this is a warning because this is a sensitive operation you should not be just randomly doing it do you really want to remove all the stopped container because you could have reused them maybe there's some volume in that maybe some data is there I don't know are you sure yes I'm sure and it removes all the container so we can see this is a really solid command but very dangerous also and we're gonna run this no containers at all still we have these images so that we can spin off things whenever and wherever we want we still have a lot of volumes that is also there and we can just use the command guess what would be the command for volumes yep you get it right Docker volume and of course LS and here are all the volumes available so whenever there is a database that is being created it requires to store all of this database information somewhere and since this entire Docker system is a virtualized system that is why you see these virtualized volumes are being created it is almost like you can say some space of the disk is being allotted to that particular image that hey if you want to keep all of your files keep it here but you cannot access them directly here there is a lot of ways a lot of heter queries behind the scene that Docker does but you cannot just go go ahead and find them and do an LS and can see them there is a bit different way of finding them we'll talk about them later on right now let's try something different with enough of postgres let's move on to different database now because that is where we are going to learn so much everybody's favorite mango and again you saw that in the postgres we didn't need any information or expertise in the postgres similarly you don't need any expertise in and you will be able to learn and deploy multi-container app in the dot in the docker world with the manga so I can see the command is really simple which says Hey I want all I want to do is uh Docker pull let's go ahead and copy this command you obviously know what this is going to do it's going to pull an image of for me which image which version of the if you say it latest you are correct if you didn't say that you should say at least in the comments that what is the latest version and all of that so that is where we are going to go for all right so this is where it downloads the manga DB and there we go now in the meantime let's study what all it has to say and offer so obviously we know what is and it says Hey start a server instance you can just name it in the detach mode and then it's going to run now to connect the mongodb from another Docker container you have to provide some information all right we'll do that and then it also says if you want to write them up ah interesting if you want to write them up we can just use all these options restart always interesting we'll see about them all right so this is the basics it gives us let's say since it is saying me directly that to start a service of the all you got to say is Docker run name it if you want to use the detach mode and give it a and colon tag we don't need to give tag we are using the latest one all right let's see what is there again I would love to verify this time I will not verify from the docker GUI I would verify that from the images because I know the command Docker image LS and let's see all right we have a image we're going to go ahead and say Docker run and this time I want to run I'll name this one as well and I'll call this one as my one and I'll say that hey which image do you want to use for it I want to use it in detach mode of course I want to keep my terminal free and I want to use the image which I just downloaded so now you can see that it is not difficult to pull down any image and run that image now the problem with that is that I have just got this one here and if I go ahead and do Docker container container LS it gives me that now this time notice here the is running on 27017 all right that's great but how can I interact with this because right now is this 27017 this is the only way to interact and there is one more problem what if I run another instance of will I be able to interact with that nope this is exactly where I told you that we want to learn about the port mapping that one version of the postgres is running 13.8 the latest is also running and we want to map them onto a certain port on my host machine different port for them and we'll learn about them so we're gonna go ahead option and let's see that if we want to learn about the docker we'll just remove the container and we can see that this uh this Docker the basic Docker command let me just find that Docker let me just go ahead and search for that that hey is there something related to Port uh we should actually be searching in the search is there search box nope okay all right let me just show you that how this can be done it's actually super easy now first of all let's go ahead and stop the container so we're going to go ahead and say darker stop and provide my one okay and we also want to run a docker and we want to we'll we'll just not prune it right now we'll just do this later on right now let's just run this okay so first step is Docker run we know this one and we also know that we want to run mango we also know that we can call this one as name and we're going to call this one as uh my Dash mongodb and now there's an option known as Dash p now Dash p is a port this is where you actually mentioned that which Port from the host you want to open up so that that Port can interact with the port of your image or the container container would be right word here so let's just say I want to interact with port 4000. and I want to go ahead and say what are the default Port of the is now yes this is something that you have to actually Google out what is the default port for postgres for MySQL for and luckily in this case we have just seen that so it is 27017 all right so this is good so far working out good and we want to just run this let's see what happens when I run that and it says hey it says Hey Docker run requires at least one argument and probably I forgot to give it that hey it says hey this failed error connecting that so there's so much going on wrong so we are not able to make this one connection uh connecting to the mongodb okay running a command in a new container first let's just verify that we want to remove all the container because it might give us some issues let's see and start fresh so that we can actually understand this is a really important command and oh my bad I forgot actually give an image to it my bad okay notice very carefully what is happening here Docker run is the command responsible for running the image we are giving a name to it and then we're also opening up a port on my machine 4000 to the machine that is giving to me so remember the first one is my machine the host I am the host and this is the image so let's go ahead and hit enter and now it is giving me all of this so I'm able to do this but I forgot one thing can you mention what did I forgot yes I forgot a detach mode I'm gonna go ahead and stop this and there we go and now I want to run this again but when I run this this time I cannot use my mongodb so I have to mention dot one and I have to mention this in the detach mode so I'm going to go ahead and say Dash D and hit enter now the container is perfectly running and it is running on a detached mode on a port 4000 the advantage of this is that I can actually use the same version and call this one as two and can use another Port maybe 5000 maybe 4001 whatever the port is free on your machine I can run that and now notice here it says Port note available exposing 4000 so there is already some something on my system which is running on this 5000 I can go ahead and change this one I'm pretty sure that 5001 might be free on my machine there are a lot of other services running on my computer if I run that it says uh uh to already in use so my bad that container is already so either I have to remove that uh so let's go ahead and say that hey this is there I want to remove this one I'll just delete this and yes from the command line also you can do that let's hit enter and there we go finally we have two machines one is running on 4000 and one is running on 5000 same images same tags same services so easy to do that now if your application is using to or want to use two different maybe you are using uh node.js maybe you're using Ruby on Rails python whatever one application you can just say hey this is my mongodb name the container is mongodb then mention it instead of localhost mention this my mongodb2 and then colon 5001 that is all that is all you have to do to run multiple images or multiple applications on different uh different databases how cool is that all right so let's go ahead and now work on with that so I know next thing is that my machines are running mongodb is running but sometimes there is something wrong there uh container seems okay as of now but I want to really know what is happening in that container now this is where another command of this Docker actually uh gets your attention which is Docker logs now this is one of the most used and important command and there are a lot of options now notice here uh this command there's a lot of nodes up here but there are a lot of options here details since dash dash tail to find out the line number above the logs and all of that so this is a command which is super helpful super useful to know and find out that what is happening where it is happening because right now we have no interaction with the container we can say just because we are able to see that okay this is running this is running but what they're doing internally what is the log whenever a web is making a request to that what kind of logs my database is providing what is the error that is coming up so these kinds of interaction is necessary and for that we're going to go ahead and say Docker and we're going to just provide a logs and notice your logs is really simple we have to just say space and then provide the container name now I have a utility installed on my system which actually helps me to suggest some commands it's a fake right now it is only available for Mac but I can just go ahead and say I want to know what is happening in my mongodb1 I go ahead and hit enter and it gives me all the logs that all the things that we were initially seeing without the detach mode this is all giving me in case your application is trying to connect with it it will also give you that and by the way now you know all the options as well go ahead and give it a try that maybe you want to do some follow follow the logs or maybe you want to provide some restricted number of lines maybe you also want to show timestamp there is some nice example that how this is going to see notice here they are using the busy box and that's why a lot of tutorial also use that it's it's a common thing using a busy box and you can provide all the outputs and everything so this is what the basics of the logs is remember log is super important one more last thing before I uh get over with that so in the logs we can just go ahead and say Docker PS and it gives you the ID you can actually provide this ID as well so for example I can just copy this and a Docker logs and then the container ID and a lot of time you're gonna see that people actually like to use uh simply the docker ID instead of the names I find it no difference at all both of them are reference points toward the same container so you call it as with the name or with the ID it's just the same it's like almost calling your laptop as laptop or with the serial name I found it yes of course in some big uh corporate environment where hundreds of containers are there having the serial name or the container ID is much more reliable but we are on the tutorial this should be easy all right okay now we want to build now we know that how the can be done and all of this now we want to actually go ahead first I'll just like to prune all the containers so notice here we are going to go ahead and say Docker uh container and we want to use the command of prune and I'll say do you want to remove all stopped container yes uh so one container was deleted is anything else running uh yes there are two containers which are running I'm gonna go ahead and say hey stop that I'm trying to do things with it multiple different ways so that you get an idea that it's not all just command line you can do it from here there it's just all the same thing so we have stopped it from here but I can go ahead and prune them from here and last time we were actually deleting them from the GUI same thing no such high profile thing hey do everything from terminal wherever you feel comfortable and wherever you are achieving the job that is what is important all right now let me show you one more interesting stuff that we are going to use in this one so we have just seen that mongodb is here but there are also many many images available so there is one more image which is known as Express so what this is doing it is a web-based mongodb admin interface written with node.js and express so instead of rewriting an application this is an application given to us by Express people and they are saying that hey obviously people want to deploy mongodb and mongodb might interact with multiple applications so here's a database and there is an application which wants to interact a lot of tutorial Works through and in fact one of my later portion of this tutorial work through with how you can create an application and containerize it but the idea behind the scene is here is a mongodb container here's a container that Express guys have written this container is dependent on this mongodb so can we make a connection between them and what can we learn by building that connection because right now this application is built and given to us by Express but this could be our own application and we might want to connect with the mongodb it's the same database so this is what I loved about this section of the tutorial you don't have to build anything you don't have to have any of the code that you want to write maybe you are well versed in PHP or Java still don't want to do it so this is the best idea this is a container I have told you it is written in Express but equally it could be written in Java anything else the goal is here's the application given to you by a developer in the container format and you want to put that or link that with the mongodb container given to you by the mongodb guys container talking to container that is what the devops role is and that is how you work on it's the job of a developer to containerize the application in the best possible manner later on in one of the YouTube videos I'll walk you through that what could go wrong that is also important but right now this is the idea this is exactly what we want to do the goal is simple connect this Express with the mongodb let's see what all it has to do it says hey how to use this image you want to run it through some Network we'll walk you through with that and then there are some of the configurations here so me config mongodb servers some notice here when it says me config mongodb server it is giving a mongodb a name and also we need to map this up on 8081 so this is where the Express actually works on so 8081 is the port where it actually go ahead and work on with that so first what we're going to go ahead and do is learn on the mongodb and then we are going to make it up and running mongodb and then we are going to come on to the express and we are going to make it up and running and we will see that how or are they able to connect with each other or not all right so a lot of things need to come up I'll just open up this uh into one more URL so that we can actually go ahead and have this container of mongodb and can see some of the environment variables of this one so first is so here's the and there we go and we can see there is a lot of references available for that and issues and all of that and one thing I wanted to mention here is this part now notice here I told you that there could be a dash e for environment variable this is another way of writing the environment we will learn that during the docker compose but here we can see that there is an admin username there is an admin password and then there is a connection URL also that you can mention if you wish on on the environment variable so now we want to configure a command in such a way that all these information are given to us all right so let's go ahead and use that and by the way in the mongodb in the postgres there was always a default password my secret password but in mongodb you can actually change that and provide your initial username of like here it is has given as a root or you can give it as an admin here is the password you can give it as a simple password or an example whatever you like so this is what we are going to work on through that now also uh they don't mention it but one thing which is important and I'm pretty sure a lot of you understand this already is here is your mongodb here is your application by Express if they are on different network it won't work so we also have to keep a worry about how we can provide a same network for both of them and this is how we're going to do this we're going to go into the documentation and we're going to see that how we can provide an option for Network so we have just like this we do we should have something like Network so uh let me just search for that otherwise I'll walk you through with that I just wanted to show you that there should be a search option here uh that would be really nice all right no search options so there is a command just like in the docker which uses a Dash Dash net to provide a network specific information but looks like it should be here somewhere let me just search here it is just find out Docker Network so here you can say that we can have a network create and all of this so let me just quickly have a look on the docker Network so Docker also have this network command and you can see there is so much more you can do in the network here as well so just scrolling it a little bit here it is we can actually connect to a network we can create a network we can provide a Docker Network create there's a lot of option but not only this yes you can go ahead and create as many Network as you like but the at the time of creating an image there is a way of creating a network and then obviously the second image also uses the same network we are going to use that all right so now that we have found enough the things in the documentation let's try to craft this command first I'm all worried about is the mongodb so let's try to run this command and again we're going to use all the options so I want to run a command which is on this is the by default but I don't want to just run it like that I want to provide provide more option the first option that is there in my mind is Dash p go ahead and provide so 27017 is going to map with a 27017 and by the way you can also provide a space provide it or not that's same so and this time not trying to give it any uh strange Port because my application might be dependent on that on the default Port so in this network I'm just opening up the default Port of this one okay now I just uh find out that there are some environment variables in the image that I really want to configure so in the uh here are a couple of net to environment variables I want to copy this I want to provide them so copy this and we're going to say Dash e for an environment variable and I'm going to go ahead and say hey this is my me config mongodb admin username and the default username I'm going to go ahead and provide is admin and then I'm going to go ahead and provide a password as well so I'm going to go back here I'm going to use this one the way how you provide more environment variable in the command itself is just by providing Dash e so as many variable as you have you have to provide it not a good way but yeah this is how it works I go ahead and provide a password I'm going to go ahead and say equal and I'll say pass word all right there is also one more that you can provide a URL and uh all this one here we don't need this right now I'll show you the reason why this is all but we don't need it I'm going to go ahead and provide more option notice here we haven't yet given a name to this one so I'm going to go ahead and say dash dash name and I'm going to call this one as DB there is no image right now no container which is using it so should be fine if not we'll just come back and change this one the most important command is Dash Dash net it gives you a simple Network that you can go ahead and provide this I'm going to go ahead and call this one as simply Network all right now also you might want to run this in the detach mode that would be really awesome otherwise it will just consume entirety of the terminal so I'll just say Dash D I am pretty sure you didn't like the way this is a really long command not idle way yes there is a way how you can actually write this command in a file and can do better ways but first we need to struggle that what are the problems we are facing that other method is better than this one so we're going to do this exact same thing in two ways first the tough way not so good and another way which is easier way and where you can manipulate modify these commands much easier way all right let's go ahead and hit enter so notice here it says Hey container Dash e invalid container Port uh so yep my bad I actually wrote accidentally all of this so we're gonna go ahead and remove this uh 270 my bad wrong place of the argument so not a big deal we can just fix it in an easy way two seven zero one seven colon 27017 and that is another reason why this is not a perfect way of writing the things hit enter and now a container is spinned off we would love to re-verify this I'm gonna go up here in the dashboard and I can see that this container is running not giving me enough information no it is giving me the ports and everything are here I can go ahead and click on this it opens it up it looks like you're trying to access the mongodb or HTTP over native driver so basically it's saying it is working you are just trying to connect it with the browser not ideal way but it is working it is working so let's go back up here on the dashboard and there we go we can see it is all available with all the if you want to click on view details you can and it will just give you all the logs everything GUI is not that bad it has its reputation but you can see that this is all it is giving is all right so one task is done now let's move on to the another task we definitely now know that this is running on a mongodb network so by the way you can go ahead and click on the dashboard and can find out that this is running on the network so I sure I think it should come up in the view details and uh it should come up here so packages mounts ports all right and it should be somewhere here the network information not sure where is it in the GUI never never saw that all right so my let's just assume that my network is lost so there is a command Docker Network LS I lost literally lost what are the networks available so there is a command Docker Network LS to find it out let's see if it helps me so we're going to go ahead and say Docker Network LS and all right so there's a network Network which is available to me and yes I'll give you on that that this app right and Bridge and host the the bridge is default the host is my host and this is something that we just created this is you can absolutely ignore I was making a video for the upright guys this is this comes from there all right so I know that now I have gathered the name of this network good so I can see that how I can use this command I can run the network on the same and provide a dash e option of me config mongodb server that means I have to give the name of my mongodb remember it is not the mongodb name it's asking for the container name that is what the name reference is here and I have to run this application on Port 8081 all right but this is not all we have to actually provide more options it's not asking it but remember it just knows the name of it it doesn't know its username it doesn't know its password so all these options we have to provide all right so let's show how we can go ahead and do this and by the way you can find all these options this image is much better and the details are much better so here it gives you all the options of admin password and username and whatnot all the information now I will walk you through of writing a little bit better way of writing these images again I'm not a big fan of writing it this way either but it's a little bit better than the last one okay so what we're going to go ahead and this time run this Docker Express image express my bad we're gonna say Docker run and we want to run in detach mode and I'll just use a backslash the moment you use backslash it will not terminate your command but we'll move you on to the next line so that you can actually see what all you are doing here there we go this is all great now first thing we want to do is provide a port we just saw that the dash p is 80 81 which is going to map at 8081. so on my machine I have to open the browser and say 8081 is the port where I want to connect and the second 8081 which is mentioned here is where the application of Express is running all right got it okay so moving further we are also going to put a slash because I want to keep on continue writing this command I will provide a dash e option and then oops Dash e option then I want to give environment variable name so I'll just first and come for this username because we actually change the username if you remember this was admin password was password not the strongest one not the secure one but we'll copy this come back here and we'll paste it here and we'll say hey this is now admin this is what we gave to the mongodb okay don't forget to put a slash otherwise your command will break we still want to give more environment variables so let's go ahead and give it Dash e let's go back the password one copy this there we go and equals password better than the last one this way of writing the command still not the best way and hit enter make sure don't forget slash there we go now we also have to give it a server name which I told you it's really really important for this and where is the server there we go copy that provide a dash e and we're going to give a server Dash equal remember very carefully this is the container name and you have to name your container the previous container we called it as mongodb write it exactly same to same this is important for its networking mongodb alright don't forget the slash because we have more variables coming in hit enter let's go back on to this now notice here we just studied that this actually requires you to pass on dash dash Network or Dash Dash net whatever is your favorite one and we have to provide the network name so our network name is really simple let's go back up here our network name was Dash Network so let's go ahead and say Dash Dash net and this was let me re-verify again mongodash Network and again don't forget the slash because we have more things might coming up okay and we also want to give it a name so these things you are familiar now and we're going to call this one as Dash Express or my Express app whatever the app is and uh what else we want to give it uh name of the image so the name of the image is Express so we're going to go ahead and say Dash Express so let me just go back and this should be the name Express rest of the thing hopefully are there and uh should be all good I'll still just for the safety purpose I'll just copy this entirety so that we don't lose it yes this is what happens when you write too much of the big commands instead there should be a way of putting all these things into some files so that we can have a better option so we're going to go ahead and say Express hit enter obviously it will not be able to find this image locally so you obviously know it will go on to the docker Hub and it will just try to bring the layers of all the images and gonna just take a couple of minutes and there we go now we have this newer image which is also working okay all right let's go ahead and see into the dashboard okay both of them are uh this mongodb is running this is exited so what is happening with this one why this is exited I have no idea on that now a couple of ways you can go and click on view details and there are logs here it says authentication fails so there is something which we might have missed in providing uh the admin or the password or something so notice here it's a password uh probably we added an extra space ah should be there so authentication has failed let me check what did we give did we give it a root or password at the time we created this ah we gave it an admin and the password was password so should be all good admin and password the server is mongodb and Bongo Network mongodb let's try it one more time so this time we have the image but it failed so notice your logs are really important all right so just found out the bug and this will happen to you as well so that is why I always say reading the documentation is important that's where you resolve your bugs so we accidentally actually copied the environment variables from here which is mongodb admin username this is not where we should be actually setting up the environments so this is where the environment variables are and again it should be written a little bit better in the mongodb there should be environment variables list but it's not so this is where we should be getting the username and password which is root username and root password initialize time we were not giving it so obviously we have to actually run these commands again not a big deal we can actually go ahead and do that again so what we're going to do is open up our terminal and before opening up the terminal we'll just cancel that container that is running the mongodb so let me go ahead and move this up so this mongodb needs to go away in fact both of them can actually go away so this container now we can actually go ahead and delete this so the first thing that we're gonna do is we have this Docker run command which is having all these details so we need to actually change this so copy this clean this and paste it up here now what we're going to do is we have to remove this one up here so let me just go ahead and first instead of admin username and all of that let's go ahead and copy this one this is what we want so there we go let's first go ahead and remove this admin part so there we go just remove this and yes really bad way of writing the commands I'll show you the easier way of doing this and similarly the password also should not be like that and there is one more thing we are learning so no worries on that part all right so let's remove this go back here and this time the password copy that and this time we are pasting the password so all right so this should be great now notice we are having the initialize the root admin and we are providing the network as well although we have created the network in the past but shouldn't be a big deal and it says Hey invalid container Port again this is the same command which we which we had some issues we're gonna just remove this and provide the port on to place where it actually belongs so which is 27017 colon 27017 all right again you will also fall into these kinds of problems so very important that I also share these trouble information so that you know how to troubleshoot them let's go ahead and hit enter now a container is being created fantastic let's go ahead and work on with this long term man were giving the same admin and password here as well we have walked through this command in detail in depth now we also have this image so this should also be fine now let's see if both of the containers are running or not we can see that both of them are running and I can go ahead and open this up and there we go so this is the default way of how you are connecting with your application and this express application connects to your mongodb let me show you and prove that to you if I go ahead and stop this container this will automatically close this one and we will not be able to access this if I go ahead and stop this for a minute notice here this is still running but if I go ahead and come this because the database is not connected it will just keep on rolling and will never connect to the database so this proves the point that we can actually take any application and if we somehow get a containerized version of it with proper environment variables like what is the database URL what is the port you're looking for that's it we can actually host any application connect it to the database that is all what we want now we're going to go ahead and start this again and now if this goes notice here if we reload that instantly it comes up back so this is the basics of how we can actually go ahead and and work with that but we realized quickly that this is not the way this is not gonna work through that we have all these commands writing into the terminal this is not going to work through we need a proper way in which we can have a file can write all these things into a file and if something is wrong we can just go there change these things and voila it works fine this is exactly where Docker compose comes up right now this is just two of these containers there could be uh five containers ten containers and more which needs to be run or spend off at the same time this is where the docker compose come up it is a simple way of creating files and running that so we'll learn about the docker compose next all right so we saw that we can actually create multi-containers can also interact with them each other and it's really common that we have a database we have an application which is talking to database maybe multiple application talking to database but it would be really really easy that if we don't have to write these long commands if we make any mistake go back we can actually go ahead and easy find that by using the docker compose in the initial phase I told you that there are two commands which we actually majorly Focus Docker and Docker compose so now is the time that we have a requirement of Docker compose and we study about them so first obviously we're going to go on to documentation I know a lot of you don't like it but this is the best way of learning anything darker and darker compose so there is a darker compose CLI reference we will be actually going through with that so notice here there is a new Docker compose version too and all of that we'll be studying the latest one so this is how the docker compose work that you just provide a dash F option which states the file and provide it a file name the file name is written in a specific format the declarative format known as yaml I do have a yaml crash course on my channel check that out in case you are not familiar with that it's a declarative syntax in which you don't write too much of the code like loops and function but rather that this is what I need a declarative approach and this is how all the options are here there are a lot of options here like for example up we also have the option to bring everything down stop and images and all of that and here this is how we actually go ahead and write the docker compose files this is not really the best example although in the documentation there is a butted down example but don't want to bring that up it's really but a deep down I will walk you through personally that how we can actually write the docker compose based on all the files that we have studied all all the commands that we have studied it is super easy to actually understand that and then we'll come back onto the documentation so I'll just minimize it this is all I will also minimize this for a brief and we don't need this guy so what we're going to do is we're going to just simply go ahead and create a new folder here so I'm going to go ahead and the folder actually goes on to my other screen let me just go ahead and bring this up so this new folder actually we don't need a new folder let me move it to bin actually we have this already folder uh there we go the devops folder it's already available in which we have the code files which we are going to talk later on right now I'll just create a new folder here which is going to call this one as uh DC for Docker compose short form and I would just love to fire up a vs code uh there we go let's drag and drop the stalker compose into vs code and I prefer to use vs code as my code editor because of a couple of Reason one big one is the extensions and here what we're going to do is create a new file and feel free to call this one anything we are going to call this one as Docker Dash compose dot yaml or yml whatever you like to go ahead and call it feel free to go ahead now it's not really always compulsory to call it as Docker composed at yaml it could be really like hitesh.yaml superman.yaml feel free to anything uh just call it anything now one thing that I have installed on this is a rainbow indentation which I highly highly recommend everyone to actually go ahead and install this so if I can find that indent rainbow so it's a plug-in indent rainbow the yaml files are heavily heavily dependent on the indentation what comes inside one category or another component is all based on indentation yes it's almost like python a little bit more stricter than python so having an indentation rainbow as your extension is super super good it will help you to make less mistake to figure out which one is inside what and all of that so I highly recommend this extension so go ahead and install this by the way there are many other options like this I tend to use this one so I'll just close this one and go back so this is my Docker compose yaml now the way how the docker compose file works is really really simple the first thing that you always write is a version and the version we are going to use is the third version this is the latest in the modern you don't have to write three dot something you can but just writing a generalized version 3 is good enough that is the step one now if you remember we wrote two commands one for one for Express yes these are containers and we divide these containers as Services yes we call them as Services service one is mongodb service 2 is an Express container express service 3 could be something else so this is how we go ahead and write that so the first thing we're going to do is we're going to write Services just like that and then this is the most important part hit the tab now notice here there's a small color highlight that comes up this is where you write the first one we want is mongodb and the second service oops let's use a colon here and the second service that I want is Dash Express and a colon so these are the two containers that I want now there could be more containers that you want to write but these are noticed here these are all inside service and this indentation is something that is asking you to write this for example there is also something known as Network and volume so these all go in the indentation level of services so this is where you can write your network but hit the tab that is the most important part we'll not talk about the network yet we'll come back onto this one let's first write what are the all requirements for the mongodb if I bring back my terminal up we saw that there is a lot of things here like for example we have to say Dash p we accidentally wrote wrong Port we also have to write these commands these arguments we made a mistake on this one that's fine and then we also need to mention the image and all of that so we have to write all of this up here let's start with the mongodb the first that you always are going to write again remember there is a tab the first thing that we write is image and the name of the image is mango it could be latest it could be version uh 3.4 whatever you like I want to use the default in most of the production level compose file you're gonna see that there is always a version they don't rely on the latest one latest could be really dangerous one so this is the first Common option the second option is to Simply write a ports so this is how you go ahead and write your ports and the ports is written in an array format there could be a lot more Port so make sure you hit a tab here onto the port and then write a dash then one space and then we are going to mention the port notice here there is a host port and container Port this is the format that we want to use the default don't go with that we want to go with 27017 on the second one is also same two seven zero one seven so this is my host machine and this is what the docker composed or the docker container will give me this is the basic now comes up the point where we've made a mistake so we'll remove the indentation because this is not inside Port this is actually environment so we're gonna go ahead and say I want to write environment then you have to mention just the name and the value so we're gonna go ahead and take it from the terminal this is the correct one that we used username copy that go back here and the value was admin feel free to give it any other name value as well I'll duplicate this one and we'll write another one which is this copy that and write as many as you like or as many developers environment variables are given to you by developers so that is all what we have to write now notice here uh mostly we have written here so that is all fine uh we are not going to write any network we yes we studied a lot about that there is a network there should be all in network but here is a fact whenever a Docker compose comes up and all the containers that you have mentioned in the docker container or dot Docker compose right now we have two but there could be five automatically Docker compose creates a new network and put all of your containers in that that is default that is happening you may want to write to give a specific name to that Network that is fine but by default all the containers that you mentioned in the docker compose shares the send Network good information all right now let's go ahead so this is all that we want as of now and then let's go ahead and write the Express now again the first thing we know that there is an image oops my bad there should be indentation the image the image should be Dash Express we studied it for pretty long then we're gonna go ahead and say ports and the ports is going to be really simple hit add tab then say Dash and then we want to go for 8081 and that will be mapped to 80 81. so this is something that we have mentioned next up remove the indentation and write the environment and again it's a key value pair so let's go back here the first is this one so copy that and we're gonna paste it up and the admin notice here how easy is it it is this time that I can just go ahead and say admin otherwise mistake you write the entire file again uh entire command again not really good copy that paste this again this time it was password I knew that easy to debug also I'll duplicate this one the third one is the name of the server copy that and I don't have to worry about this is the name of server at line number three I'll copy that and paste it up here super easy super easy okay all right so this is all what we need this is still not going to work uh but yeah good good enough to give it an attempt and see what is happening now let's go ahead and open up our terminal and we're gonna also open up this dashboard all right so this is what the dashboard is giving us let's see what is happening right now these are all running so obviously this might consume my port so I'll just stop this one and stop this one as well let's see what is happening in the container world when I run this one so obviously this is on the desktop and I have this devops and inside this I have this DC and I'll just hit enter by doing Ls I'm able to see this file this file could be named anything I am saying Docker compose and then Dash F to give it a file name and that is Docker compose dot yaml let's see what happens if I run it as it is if I run it as it is it says hey this is not a perfect way of running the command and let's see what else is here it says hey there is an option of Dash up or just directly up it creates and start the container okay we got that that what mistake we did so we're going to go ahead and say up and let's hit enter and notice here let's study this command this is the most important part of it it's going to keep on doing the things and it probably will crash or something but the most important part is if I go really long up where it is all is happening there we go this is somewhat we yeah this is where we run the command notice here it says Network DC underscore default a fresh new network was created and all containers reside in that then it creates a container DC mongodb1 and then the DC Express one so these are the name of the container now notice here this is waiting for the connection but let's see what is happening in the dashboard this is something new notice here the DC is being created here and if I open this up this exited while this mongodb is running so what is the problem why this exited if I go ahead and check out the details and I check out the logs it says hey uh network error so there is something really wrong here not authentication but something really happened let me show you what it happened and how we can actually resolve this now when you run these containers your compose file don't know which container to run first it could run Express first or maybe it could run mongodb first but we also know that this Express is relied on the mongodb so mongodb containers should be up and running first and then the express should come into the picture now there is an option of we can write the discontiner second Express one is dependent on mongodb or we can keep this Express container up and we can say that hey you keep on restarting until unless you find a connection with the mongodb both options are great and majority of the time people will be using something like hey this depends on that so for that refer the documentation and you can find it up there but I want to go into this Express and I want to just Express one more uh thing here which says Hey I want to use a restart and this restart is just a flag and you can just always say always always so as soon as you mentioned this restart it will keep on restarting until unless it finds a connection and it doesn't terminate on its own so there we go let's go ahead and try this again so we're going to go ahead and shut it down remember this container stops and everything I can just go back again and start this again things are going good and now notice here this time it says server is open to allow connection from anyone basic authentication credential or admin pass it is recommended you change of course we are going to do that but let's see what is happening here notice here this time DC is still running so we don't have to create containers and containers whatever is in my file either that goes away or that comes up so I don't have to delete the containers it manages that thing for me for the cleanup as well and this is running and this is also running I can go up here and can see oh this is good this is great now let's go ahead and just reload it works it works out of the box now let's go ahead and create a database we're going to go ahead and create a database yes I can create that I can go into hitesh let's create a new collection so we're going to go ahead and call this one as what should I say YouTube that's a great name for a collection and this is a collection let's create a new document in it and this is how it's a key value pair so it will get an ID something like that in case you don't want to write any code just click on save it will just add a empty ID not a good way but it will add an empty ID here I will also create another new document and we'll just hit enter and I'll say that hey let's just say this is email and a key value pair nothing writing nothing much more than that and we are going to just provide a string that and we're going to say hitesh at uh google.com something like that fictitious email of course and we'll save this one uh invalid Json you should have a comma and save that now it saves the email as this field all right this is great we have successfully deployed an application without writing a single line of code and it works now let's go back on to terminal and we can see that the response are also coming up that is fine we can actually use that in the detach mode as well but no worries we are able to write this all these things syntax error so logs are great logs are great I'm gonna kill this and see what is happening in my container world and we can see that the DC is all exited exited fine great I want to run this again so I can just go ahead and okay please allow that so we are going to just remove this one and we can just click on this and run it from here as well it will again refer to the same file so let's just run this one it knows where the file is so it just starts this again and I can come back here and hit a Reload and I go on to express it still has this hitesh and all the things are working fine but let me show you that what happens when the things are here so it says delete me YouTube and all of these things so we're going to go back on to 8081 there we go and hit a refresh everything is here all right let me walk you through with a couple of more things we're gonna go back up here and hit a control l the problem with this is uh there's a small problem here let me just show you and stop this all now notice here this is all being stopped let me walk you through there is something now we need to study we have studied the images and container we have this volumes as well okay some of them are in use okay let's see what happens if I go back onto this one I'm obviously not able to link with that if I go back onto my terminal and try to make this compose up again it creates everything it is now connected I back go back to the terminal hit a refresh I'm able to see this hitesh again here why this is happening because in majority of the cases you are going to see that the data doesn't persist this is a common problem in the container and we also see we can see that we can actually go ahead and run this command let me try to show you that I can close this again and if I run this command again couple of container command remember we ran this command Yep this one so this is my first container I'll run this we have to actually remove the container or have to run the change the command instead of Run start we have to do that but given the fact the one of the biggest of the problem in the docker world is that the data doesn't persist that means the container is a removable item it's a detachable item anything that you have mentioned or have used in that that actually gets away from the container now this is a good thing because if you are making any sensitive applications specially like a code engine there you you have a chance that somebody might throw up a malicious code you have to execute that maybe that code might entirely corrupt your system but you don't worry too much because it's a Docker container everything just goes away after that but in this case we want to really have this data and we want to understand what is something that is keeping this data now for this we are going to understand about the docker volume now this Docker desktop sometimes in fact most of the time creates an automatic volume for you especially for the databases that hey I'm pretty sure or you might want to have this database you want to keep it there so that is why it is up here now this is where something interesting comes into the picture now I I actually ran all of this before recording this video that is why this persistence is coming up but I'll show you that how actually you can go ahead and do this I'll open up the VS code there we go and one more thing we can mention just like we have Services is the volumes so we're gonna go ahead and say hey we want to keep our volumes as well just hit a tab and we're going to call this one volume as let's just call this as Dash data and then this is a syntax hit enter header Tab and then say driver colon local so basically it's saying that hey I'm not using anything fancy it's just the local drivers to have a data mango there is there we go now wherever your database lies because remember this is not something which is persistent this is what we want to make persistent we can go ahead and hit and enter here and then we can go ahead and say uh I would like to change this name instead of data I'm going to call this one as my mongodata because I actually use this same example in testing out before recording this video I'll come up here make sure this is on the same indentation level this is the common mistake we're going to go ahead and say volumes and then you can mention as many volumes as you want to use and notice here the volume that we want to use this time is this my data so you have to just copy this and paste it up here so now this is using and then use a colon now this is container path that means I have given a name to the volume that hey this is the name of the volume otherwise we have seen that how ridiculous the name actually comes up in the volumes yeah this could be like anything this could be anything you have no idea about the ID so better to give these volumes a name at least in our file so so that I can actually refer this now whenever a new container is deployed of mongodb or postgres there is a specific path only which these containers or these database store all the values so we are saying that hey I am giving you a volume which will be permanent regardless that container goes or not it will always be there and I'm calling this as my mongodata so whenever this should be mounted up in the container use this mongodb data and where it should mount it slash data slash DB now this is a default path of mongodb this is a different path for postgres this is a different part for my SQL so make sure you know that where you are actually going ahead and doing this once I save this and I go back onto terminal and I run this Docker compose again let's go ahead and spin this up and this will keep on starting keep on starting until it was able to actually connect this all this so basically now it is all connected and I go on to this localhost hit a Reload notice this time it is gone because I have mounted a different volume and this is the default Behavior because randomly it might generate a new volume for your container and there there is no Persistence of the data what I can do now is I can just go ahead and create simply my hitesh as a new database table or document in this case and I can go ahead and say that hey just there is a delete me there is a view collection name I'm going to call this one as test call for cool that is also good and there we go we have a data persistence here which is creating the volume like that let's create a new document save that and there we go now even if we stop the container we can actually go ahead and stop this and we can map it up to different volumes that is also possible so if I go ahead and stop this obviously I don't have anything so it is gone and I can go ahead and try to make it up again and this will be up in a second there we go and I hit reload and this database is always going to be there now giving you the fact also want to demonstrate something else let's just say this time you are not calling it as my mongodash data let's just say we call it as uh something different data dash one so this is obviously a different volume that you are creating so now this file will be loaded up so we're going to go ahead and change this name for the fun sake save that go back on to this obviously this needs to stop we're going to make this up and running and this should be up within a minute and anytime now come on there we go I go back on to this and I hit a Reload and there we go this is gone now I'm gonna go back here and notice the fun I'm gonna create a fun database I'm not gonna do anything inside this but I can go back on to this vs code and I can say that instead of my uh data dash one I'm gonna go ahead and say I want to connect with this original one so you have a volume which is permanently saved and I can go back hit a Ctrl C start that again anytime now and we can go on to browser hit a Reload you get the idea this is the data persistence and yes data persistent you can study a little bit more so that all of your files code files and everything can also be stored so this is the basics of how the docker compose work obviously you should more uh and again it is also one more thing I want to mention before we actually go ahead you can hit Ctrl C but control C actually doesn't close anything you can see that still into the containers we have this DC there is also a similar command here which says Docker compose and you can bring everything down hit enter and it will remove the network and everything and notice here all the things are gone so this is the basics of how Docker works and remember we have not coded a single line in Python in Java in JavaScript in Ruby or anything else and we still we do understand that how the database Works what could be the connection what could be the connection string what could go wrong how to introduce environment variable and everything without touching a single line of code that was the goal with this course now couple of more things I would like to mention here before you go up onto different exploration of exercise and projects I'll include two projects here in this video as well which will be how you can actually containerize a python application how you can containerize a JavaScript application as well and maybe I'll explore more in the future as well so this is the basics that we're going to go through one more thing one more thing before we go ahead and work on with that in the later on videos or this section same section of the videos I'll introduce you that how we can push these images onto the system that will also give you a more clarity towards the code perspective that how we can write the basic bare minimum code it can expose our application on certain port and that can be containerized and if there is a database Connection in that application this is exactly what you can do to connect that with the network database available in the container so really this is a big picture overview and I hope this uh sort of Crash Course has helped you now uh this is something I want to mention just one last thing is you can create the repositories these are public repositories that you can mention but also want to mention that this is not the only way of how you can actually go ahead and pull the docker Hub or Docker repositories the default is mentioning the docker Hub or Docker repositories but AWS also provides you uh uh Docker registry which you can use a Amazon elastic container you can host your images here as well there are a lot more options it's not like just the docker Docker is the most common first one and the public one which is available and the default one but there is no shortage of such container Registries most of the companies like to keep such images to them privatized themselves and they use mostly Amazon or Azure and all these cloud services to actually do that rest of the Thing Remains same so your Docker Docker compose containerization and all of that that remains same so this is how it works this was only the important information I want to mention now all those who have understood and studied are this far congratulations yeah you now all know about the docker in and out now the next videos are something which is going to help you to dockerize and push your application image onto the docker Hub both in JavaScript and in Python I hope you are excited go ahead hit that like button and subscribe as well in case you have enjoyed the content I'll definitely bring more such exhaustive lengthy and meaningful content for all of you that's it for this video let's catch up in the next one hey there everyone thanks here back again with another video and in this video we're going to see that how we can convert a flask app which is made in Python in a Docker image now this is a really basic flask app that we have created which obviously runs on a web and just give us a hey message hey python now flask is one of the most easiest way of how you can build a simple python application on the web or maybe just apis and yes there are other ways like Fast API and Django and a lot of database could be involved but slowly baby steps we're moving through the Journey of going through with the docker so this is the most easiest one the whole idea behind creating these kinds of videos is so that you understand a little bit Journey about the devops and sometimes you even want to know that I don't really understand what is the business logic in these applications that developers has coded I just need the bare minimum information and wire that information I can make a container or I can make an image out of any application whether that's coded in JavaScript or in Python let's just assume I don't know python let's just assume I don't know even a tiny bit of java and still I'll be able to host these application the today's turn in this specific video is for python flask application let's go ahead and see how we can do that this is the one of the most easiest one that you can do so I don't even need to check what's there inside the index.pi the first thing that is important for me is the requirement what are the requirement for these application now this is where you actually go ahead and interact with your developer he says hey this is a Basics last gap which needs to run on the port 3000 that's all I care and that's all I really want to know I don't know what it produces as an output what success and all of that that's the developer role we just want to put this application as an image and obviously we want to push it onto the docker Hub just for fun okay all right so first thing we're going to do is simply go ahead and say uh Docker file so that's what we want now in this case this is a python image so we want to take a base image which is going to be a python image now there are a lot of python images available both for version 2 and 3 but obviously this is a Python 3 version that we want to call up so really simple we start with the base image always and always with the base image so the base image in this case we are going to go ahead with python I'm going to hit control space and it can give me a lot of suggestions so I'm going to go ahead put Colin then again hit control space and gives me a lot of versions of these images so in a minute there we go we have a lot of version of python 2. I'm not interested in that I'm version 3 that is where I'm interested and you can see from 3.16 to 3 or 15 a lot of version 3.16 seems a little bit too much updated for me so I'm gonna go with alpine 3.15 Alpine is nothing just a strip down version a little bit lower in the size but again depends on what kind of python is being used in your application you really want to consult with your developer a little bit on that all right so this is the basic then what we do is really the basic uh this remains common in most of the applications so we Define find the working directory you can put it just in the slash but it is not a good idea so you always want to have a directory because this is like an operating system almost like and in that the slash is very sensitive directory so you want to create a new directory just like you have a desktop something like that is there so we do just the app and it doesn't need to be always like app it could be just hitesh but hitesh doesn't seem great the app is actually much better then we go ahead and simply say that hey we want to copy and the copy some information there are ways how you can copy then run the command then can copy rest over the files these are caching and all these optimization we don't want to go into that as of now we simply want to say hey copy everything that you have and just go ahead and put it into slash app so that's it we defined a working directory we move all of our files into that working directory that's what the basic of this image does then obviously we need to run some command because when you take an image which is based on python it is based on python the python is installed in that but all the requirements like flask maybe Django or something else is not present in that so we need to install that so we go ahead and run the command in case your company or you deal with a lot of python command uh you should run these few of these commands the first one is actually pip install and then we pass on a flag of Dash R which gives all the requirement in a file so which is going to be requirements.txt and make sure you don't do typo because I do a lot requirements uh should be the exact same file requirements.txt so make sure you take care of that once this is done that means in a new image which is based out of python all the files have been copied all the requirements are also done the only thing which for this basic flask app remains is exposing the port and then finally running the app so let's go ahead and see that we have seen that in the last video as well we can go ahead and say hey expose 3000 it always doesn't need to be 3000 it could be five thousand eight thousand whatever the port makes sense you want to expose out of that machine machine or an image you can go ahead and do that and finally you have to fire up a command we'll talk more about these in the series itself or the docker by the way I do already have an existing series but I want to freshen it up so we're going to go ahead and have some command and the command is really simple it's just a python file which we want to run in the same directory remember we have already mentioned our working directory that's where all the things happen we'll say dot slash index dot py so we want to run this base file and based on that there could be 100 other files and dependencies or all that this is the entry point we want to mention once you do this that's it that's your basic Docker file not too much of the command obviously as the complexity begins to increase uh maybe that's a Django file just basic Escalade or maybe postgres is involved maybe mongodb is involved there's a lot of things that can come up again and based on that we have other files even spoiler alert Docker compose is there but we don't want to track them right now at least in this video but this is all what you have to do this is a great exercise to build up a lot of images and all of this by the way in case you want to go for that uh here's a basic python file or you can just go for here's the basic python file you can pause and write that but I don't recommend this I recommend you to go on to the flask documentation let me just show you that actually it's super easy let me just go ahead and open this up so if you go ahead on to Google and just say flask uh hello world you can just go up into the a lot of files are there even the flask quick start documentation a lot of great websites are there which actually helps you out there uh we'll go on to the plus a flask uh getting started and there it will give you the documentation of how you can get started with the basic application so notice here uh this is all you need to copy uh this is the route slash on which hello world is being defined and you are just running it and that's basically it it can do all the job for you uh there is additionally a couple of more lines that you can write but this is all this is all you need in case you don't are not able to find or don't want to write it just go get it up here that's all that's all you need for the practice purpose in case you are seasoned in Python you want to write a couple of more lines of code like if and all of that that's fine if you don't write it that is also fine flask actually works without this as well all right so we got this one now let's go ahead and try to build this as an image in case you have followed the last video where I showed you how you can build images using the node.js this is almost going to be similar that with that but I'll show you that again the fact the requirement is you should have Docker installed in that on your machine at least so the way how we do it is simply say Docker we pass on a command to build and then we pass on a dash T the dash T is to give you a tag and I always always prefer that my tag should be something which comes up from hub.docker.com and your username in my case I've already logged in into this so I can check my profile and this gives me my username so this is hey node.js we pushed it in the last video and this is my username so I go up here and I say that hey I want to tag it first with my username then whatever the name you want to probably Define here so in this case I would like to say hey Dash python uh python flask would be better because I do have a plan to push up more python projects and show you more example with the Django and couple of others as well but no promises on that and this is the basics hey python flask so this is the app now again we'll talk about these tags you can go ahead and say latest this is the default tag that when you pull them image it pulls up but if you don't want to pass it on because we'll be incrementally updating it you can go ahead and say classic 0.0.1 dot release again if you don't pass on anything pass on latest that's a default tag but you can go ahead and pass on this as well once you have done this the most important part is put up a DOT this dot defines that the docker file based on which this image should be created is available in the current directory which is Docker file now if I go ahead and show you my dashboard on the docker desktop in the image we have just the hey node.js with the tag itself we'll be creating another one I can go ahead and show you by refreshing it nothing is there and we can go ahead hit run this and this is going to take just a few seconds because it's not a big image on that depends on your internet speed as well but I think it should be fairly easy and now we have got uh this Basics up here copied and all of that so I should have another image uh in theory at least so there we go python hey python flask and we have got the same tags and release and all of that so now what I want to do is I want to run this image first because before pushing it to HUB I obviously want to check out whether this actually works or not so to run that all I can say is Docker container and then I can run this app with a Dash D which stands for detach mode hey don't keep my terminal busy give me my terminal back and you keep it running in the background and then we obviously need to expose the port because it's a web application runs on a certain port and I would say hey in the docker the 3000 Port it's where running and on my main machine I can be saying 4000 or I can say 3000 wherever you want to map those Port together and then obviously I have to mention these name which says uh hey python hey python flask and I have to give it the version because otherwise it pulls up as this default I don't I haven't given that so I'll say 0 dot oops my bad accidentally hit enter okay we're gonna say uh 0 dot Z oops 0.1 Dot release that's a long one and then all I have to do is hit enter after that so I'm going to hit enter and this is supposedly in theory if it is all correct it's going to run a container uh behind the scene for me and we'll be exposing a port on my main machine it's taking a little bit while probably did I hit enter something wrong let's try to find out where it is going wrong right now nothing and the image is there all right let's wait for a couple of seconds did I accidentally run some command wrong all right uh let's let's actually close this and let me open it up as a full screen so that we can actually borrow this name uh maybe I did accidentally type something wrong okay all right one more time this happens to every one of us Docker container we want to run the container we are saying hey run it in detach mode with a port exposed of 3000 and we'll map 3000 on our real machine as well and then I'll paste this one as it is and after a space I'll hit enter and there we go this time it works probably I mistyped something I'm sure here or probably here I don't know where okay so this is now running and I can verify that by saying Docker uh container and I can say LS small for listing down so there we go container is running now let's quickly check on Port 3000 whether we are getting uh Hey python this time ah great but what if I want to stop this so I'm going to go ahead and say docker container uh stop and I want to stop zero seven six F so I want to stop that I want to run this command again but this time I don't want it to run on my main machine for 3000 all right a small glitch and now it's recording back so okay so what we're trying to do is we were trying to uh just change the port here so let's go ahead and say uh we're gonna go ahead and run this Docker container and we want to just click LS nothing so far and we want to run this so we're going to say docker container run and what we want to do is run in the detach mode with a dash P option and we initially uh went through with the 3000 but on my main machine now I want to expose 4000 Port but on the container it's always 3000 that's what we mapped while building this image so that should be fine and now we simply go ahead and mention that hey this is the image that we want to run and that's it so it gives us a 97c so let's go back up here so if I go ahead and check it out this is where Star recording stopped 3000 nothing is there and if I go ahead and say 4 000 there we go so you got the idea this first one is my machine Port this is the image Port I cannot change it once the image is being built but yeah I got the idea that how this is being done so let's go ahead and say Docker container stop and I want to stop 9d nine and I can just run uh no such container 90 or 97 my bad 97. okay all right so now all the containers should be freed up uh this means I can push this particular image onto the docker Hub so that anybody can use it I'm gonna go ahead and say darker push and I'll name this one same I'll say that hitesh my username and then all I have to do is actually I can copy and paste this one I've already got this as my clipboard so there we go so this is my username and this is what I want to call my image and of course you have to pull in the tag with this exact release otherwise if I just say it colon latest then it will pull the latest but this incremental update will help us later on as we'll be studying at the docker so this is the basics let's try hit that and obviously it will take a little bit time not much but little bit can we do a fast forwarding in the editing I think yes all right so finally it's being pushed and let's go back and see on to the docker Hub whether we got uh python as flask and there we go all right we can see that hey python flask is now available and we can see that there we go anybody can use this one of course they also have to use the tag uh this tag exactly and this will help to get them this file all right so again you noticed here that as a Docker or as a devops engineer you don't have to Too Much worry about what's happening what is the business logic and all that you were just responsible for creating the image and as you will move forward you will realize that this is the image that somebody needs to give you and you can run as many containers as you like of this exact image without worrying about what's the business logic what's this but again yeah this much of the piece you need to write and this is mostly available on the internet on the documentation or through such YouTube videos which I'm pretty sure you're gonna subscribe as well that's it for this one let's go ahead and catch up in next video hey there everyone face here back again with another video and in this video you are going to see that how can I make a simple node.js endpoint in the rest API and I how can I dockerize it and push that image onto the docker Hub remember a couple of keywords here I didn't say that you will learn I just said you will watch it because this is not a tutorial okay fish if this is not a tutorial why does this video exist now in the later on upcoming few weeks I I really wanted to make a playlist about the docker as well as on kubernetes and this is a preparation material for that I thought why to make a preparation material behind the scene why not to just record that and also push it onto YouTube so that at least you can learn something from it a big wider note on this one is this video is not about the caching of the images those who already know the docker I won't be showing you the caching because that's a part of later on videos and yes despite saying this there will be left and right comment under this video that hey this is not the optimum way you're not caching it's not about that I wanted to prepare some images so that later on I can use them for teaching the docker and this is a part of that video again a couple of similar videos will also be coming up on the channel these are all preparation material for the upcoming Docker Series so without further Ado let me go ahead and get started in case you want to follow that yes you you will be able to completely follow this along this tutorial or this watching video will give you a lot of insight as well as some of the confidence about that yes I can also do it so let's go ahead enough of the theory talk let's go ahead and write some code and fun stuff so first and foremost in order to follow along with me in this video you first need to install Docker on your system now Docker installation is not a big deal anymore it's really simple you can just install the docker desktop it's available for almost everything that you want if I go ahead into the guides I quickly see that there is a getting started guide and there is a whole lot of things that you can do with that the the easiest one is to go into the manual and I want to install the docker where do you want to install it on a Mac on a Windows or all in a Linux system uh that's all the guides are available it's just a matter of next next in case you are in Linux that is also super easy for example on Windows uh here is the desktop for Windows just next next and again they are also mentioning system requirement for if you want to go with hyper-v which is the default one if you want to go with wsl2 bag they give you all the guides so you can also use some command line utilities like chocolatey and stuff and can install that on windows so regardless how you do it it's a pretty simple install you get this application here same for the Linux as well it's available in couple of flavors the most popular ones of course it cannot be available for everyone and Ubuntu the most famous one here is the uninstallation prerequisites and here is how you install it that's all that's all it is and then you can just run the docker version so regardless of how you install that you are going to require a Docker in your system if I go ahead and fire up my terminal app I should be allowed to have a simple Docker Dash V or version and yep if this looks like something like this uh then yes you have the docker installed it says how can I find the docker version that should be here so there's a lot of commands available as long as you get something like this then it's it should be all okay let me try out where the docker Dash V yep correct so a Docker version regardless of what version is installed in the system you should have a Docker version now apart from this since we are going to be pushing A JavaScript based API onto a Docker Hub and we'll be creating an image based on that you are also going to require some node.js 18 19 whatever the version suits you just go ahead and install that I'm going to go ahead and say node-v and it gives me a version 16 and I'll update this I'll update this very soon but this is okay this is totally totally fine with that so any version should be fine all right so this is the basics you should have both of them installed now I also have this Docker up and running here so this is how it runs these days so if I go ahead up here this is freshened up I have removed all the things we have nothing in the container all the images has been pruned out and volumes is also wiped out so there is nothing right now we want to learn or we definitely want to create some of the code pieces now again the series that I want to make in the upcoming days it's not going to be a coding series but rather a devops friendly Series where we focus more on Docker and kubernetes so writing part of the code is just because I wanted to make an end-to-end tutorial you don't want to download with some files from there or something so instead of that we're going to be writing everything on our own so that's what we'll be doing okay all right let me fire up my vs code here we go and I have this folder devops and I'm going to go ahead and call this one as simply uh code files yeah because a couple of code files are going to be coming in I'll be creating a couple of more series uh or videos on this one I'm gonna call this one as hey node.js and let's drag and drop this one all right looks pretty good so far nothing really complicated all right full screen there we go nice and easy now is I want to open up my terminal in case you don't know how to open that that should be pretty easy just click on view and you can open up the terminal this is an inbuilt terminal the advantage is I don't have to Traverse into direct directories and CDs and all of that I don't have to do that and now first thing is we are going to start npm so we're going to say npm in it npm is something that comes up with the node.js so that should be fine and we also want to give a flag of Dash y so that it it should not be keep on asking us hey do you want this or that and all of that it just creates a package.json file a couple of editings that we are going to do in this file the first one is we're going to replace this start test with a start and we are going to replace this entire thing with node index dot JS all right the reason why we are doing it is simply because in the main it's already written as index.js this is the main file and we want to run that through the node utility so obviously we need to create an index file so we're going to go ahead and say index dot JS now we're going to be creating a couple of files and folders and we're going to remove them as well yes we can create the docker ignore file but that's for a later on tutorial right now we want to go through this path all right so the first thing we're going to do is install a package so that will help us to create the apis and we're going to go ahead and say npm install and we're going to go ahead and install Express now Express will help us to quickly create the rest apis and we don't know much about the express let's just assume that we're going to go ahead and say Express npm uh documentation would be always good idea all right so everything is going to come up from the documentation from the getting started guide so how to write a hello world in this one and this is exactly what they say is how you write the hello world all right let me just copy this we are going to copy this and we'll come back here we'll just paste it out that's all what we are doing so you don't need to learn that how this code actually works but you should have a fairly brief idea of what this application is about the complex business logic is for the developers not for the people who are in operations or in devops you just need to know this is going to run on Port 3000 this is common for every node.js application not the port but the syntax of how it works there is always a port there is always some kind of node environment that you have to create that's the basics of it same goes for Python and for Java as well they have their own kind of a common things that you always have to kind of do and that's what we are learning or we'll be learning in the future so what we're going to do is we are going to just modify this a little bit so that it looks uh a little bit good so what we're going to do is instead of saying res dot send let's go ahead and throw up a Json response and remove this hello world I don't like that I'll just go ahead and say this will be saying something like hey and we're gonna go ahead and say node JS all right and this is the basics we don't need to make this application any more complex but just like we have given here a slash so that the default application will throw us a response of hey node.js we can create more routes but I think for this application creating more routes is just going to create some more complexity for the operations perspective for the people who don't are not interested in the coding part so we're going to just keep it as it is all right so this is the basics of it and the application works in order to test this out all we can do is remember in the package.json we have run this start command so we can actually use this or we can just directly write a node so we're going to be running a command which is more friendly let's go ahead and say that I want to say node index.js example app is listening on Port 3000 so that's great let's go up here and say that hey I want to listen on localhost 3 000 and it says hey node.js that's all the testing is done so let's go ahead and stop this now a couple of things now yes we are going to learn the best ways later on right now the first thing I want to do is right click on the Node modules and delete this again yes there are better ways I just want to make this application little bit simpler to follow and some confidence in you so that you can actually push this image onto the docker Hub applications are important but confidence is equally important let's create a new file and call this one as Docker file and that's it your vs code might ask you to install couple of extension go ahead and install that these are always a great idea before I go ahead and do this also you should visit hub.docker.com and once you visit this this will ask you to create an account go ahead and create an account my account is a little bit older one and I published one image hello Crow four years ago now we'll be publishing a few more images for the upcoming Series so you can just click on this my profile and all the repositories or anything images that you have pushed will be available here remember you have to go go ahead and login into this one so create an account after this from the terminal itself you have to just run a command that says Docker login once you do this this will take you on the browser and you have to use the same credentials that you have used for creating the account and you will be logged in into the terminal of your computer that's all you have to do now here comes the operation part in the world of operations people don't write too much of the code but they have to write the minimalistic code that is not basically a code but more of rather a configuration file a syntactical file that helps them to push the code entirety of the code ZIP them up and push it somewhere in this case the zip is actually an image that can be utilized on multiple platforms on our local system on AWS on Google Cloud a lot of places this code is going to be used now the best part is as long as developers know the bits and basics of how to create these images as the operation guy or a devops guy you don't have to really worry about whether this application is being built in python or node.js we rarely care as a devops engineer so let's go ahead and see that this is something which is done usually by developers of creating an image but as a devops engineer you should also know bits and pieces of it now the first step is to have a from now this from is going to just simply say from where do you want to take your base image now base image is something which is available on the docker hub for example I can just look for a node.js image and you're going to see there is a lot of node.js images not JS agent and whatnot and all of these I just look for a node image yep that's what I want to look and if you look up for the tags I'll explain these tags later on there's the latest there's a slim version there is a hydrogen version a buster slim and whatnot the only difference is the the latest one is of 353 MB and the slim version is 75 MB so quite good one depends on what's your use case do you want to rely just on the basic core components of node or your application consumes lot more than node and all the packages that it offers so from where we pick up a base image and I'll walk you through what this base image is later on but right now just assume it has enough of the components of os and networking and the application that it is going to successfully run your application so we're going to go ahead and say that I want a node image and if you have installed the docker extension then you can go ahead and put up a colon and press Ctrl and space and it's going to load that what all images are available right now it says loading but within a few seconds there we go we have a lot of images available and you can see the screen scroll bar this goes like pretty good and I'm gonna go ahead and just use the slim version so it's automatically going to pick up the latest slim version not a great idea you should be mentioning the version number but yeah I give you on that we are just explicitly doing it the next step is to Define your working directory that since this is a container image everything is going to go in some place so we have to Define that I'll just call this one as slash app feel free to call it even at a slash slash is not a good idea to run your application so have it in some folder slash app slash slash YouTube wherever you want to have this one now we are going to go ahead and copy from source to destination source is current directory so I'll just say dot this is a shorthand for picking up all the files from the current directory that's why we deleted node modules because we want to copy that over we don't want to do that yes we could have created a Docker ignore file but we'll talk about them later on to the destination we want to copy all the files into slash app and yes this is the exact point where people will be shouting at the comment section hey we should copy be package.json for we will talk about the caching later on right now you can ignore that and then we're going to go ahead and run some command the reason for that is that we want to run the command npm install is along with just the package.json it doesn't work it needs that node module directories since we have removed it and we'll when we will be copying these files into the docker images this won't be there so in order to repopulate that this is the command that we use npm install this will bring back the node module folders back so once this is back that means our application is looking absolutely fantastic just one tiny more thing which you should be worried about is notice our application is running on Port 3000 right now this Docker is like it's not good to say but it's almost like a virtual machine yes I know a lot of people will be bashing me on the comments it's not a virtual machine okay let's assume right now that it is almost a virtual machine right now there is no Port exposed out of it so we need to expose a port so that we can see what's running in that machine I know okay so we're gonna go ahead and say Expose and the port is three thousand all right now final thing is the command because your application is installed copied uh node module folder is created but remember we actually ran our application by running the command node index.js and this is exactly the command and yes there are a couple of ways how we can write the command better ways bad ways we'll talk about them later on and this is it this is all the development part that as a devops engineer you usually do and even not that much this is usually given to you as an image by the developer itself and that's why we call the devops as a contribution from developer comes up a contribution from operation guy comes up and we build the ecosystem and environment for that so this is the basics of how a Docker file is being created now this is all done this is all the programmatic part of the docker now we can just close all of this and can go into uh the terminal now here comes the best part now we're gonna use a few Docker commands to First build an image the image will be based on the configuration that we have mentioned in the docker file this will be utilized it's not perfect it's not being cached but it is and the goal is to build an image also to make sure that that image runs we need to run that once we have run that we'll stop that image and we'll push this image onto Docker Hub so that anybody can pull this image and at least can run the basic application that we have created here all right let's go ahead so what we're going to do is first it's really simple we're going to say that hey Docker I want to build something and in the build we are going to provide a dash t as well now Y dash T Dash T is a tag option you can go ahead and use without t as well and it will give you a random name which is not good it will be not really great if we want to use Dash D now a little bit more of a stuff so let me go ahead and walk you through uh with the here onto the docker Hub now when you go on to the docker Hub let me go ahead and move on to the docker Hub if you remember there is always your profile name whatever the name you have chosen so if in case I check for my profile there is slash U and then your name this is your profile name and if you tag your images here that means anybody can pull your images so let me walk you through with an old image anybody can pull my image by running the command Docker pull and then my name that is my username it will be different for you when you will be creating accounts so make sure you mention that and then and after that whatever you have named your image in my case I said hello Crow but in this case I wanted to say something different all of your images will be tagged as your profile name and then a slash and then like this we want to follow the same kind of a thing all right so let's go up here so we're going to say that I want to tag all of my images with my username and then whatever the name you want to give I want to call this one as hey node.js now this is it this is good but eventually there might be some incremental updates in the images and all of that and for that the docker actually gives you a couple of more options when we search for this node in case you might have noticed there are tags and these are the tags that are available up here so notice here colon latest colon it's slim and there are a lot of version on top of that if I click on this one I'll show you that there are a lot of versions available up here a number sort of long share values and whatnot we want to follow us the same kind of a convention here that we want to tag our images something like that okay how we can do that it's totally up to you how you want to tag them the easiest way is to call this one as 0 Dot and again my bad we need to call this one as dot zero so colon my bad colon and then say 0.0.0 and this is the basics of how you start your application and eventually you make an increment of dot one dot two like that and I've already made a video about that that how these versions are being tracked in the npm are details about npm but right now we want to go just the one because this is the basic and we want to call it as this is a Docker convention dot release and yes you don't need to do it this part is totally optional you can just call it as colon latest which automatically gets up there or you can just call it as 0.0.1 that is also fine but in all of the tutorials in all of the documentation this is a convention that we want to use so I'll just go with that all right so this is my basic now one more thing put up a space and just mention a DOT all right why this dot this dot is to mention that the docker file based on which you have to create this image or build this image is available in the current directory yes in the world of Docker everything is which is in the current directory is not mentioned as dot slash but just the dot in case you are coming up from a programming background so this is the dot that means hey if you're going to look for it the docker file is just right there and this is exactly what we want now as soon as I hit enter this is going to take some time although we have used the node slim version but this is going to take some time because it runs the npm install which also takes a little bit time and all of that your system might take a little bit more time than what I have okay now a couple of things we can go ahead and run couple of commands something like docker container and we can do a quick LS that hey how many containers are there right now we can see no container ID no image no command no created so it's empty it's flushed out everything is all gone now we want to run this we want to check that whether we have image or not now just quick note I can just click on this and click on the dashboard and in the dashboard if I check out the images notice there is one image now yes there is a command line way of doing that as well but we have seen that this image pretty big but it is available now and this is entirety of my code I don't have to worry about environment what to install Ubuntu nothing it is just all there now if this image is there I would love to run this image so let's go ahead and run a couple of more commands we're going to go ahead and say Docker container and we're going to say hey I want to run an image but I want to run it in the detach mode Dash D is option or you can write dash dash detach what it does it frees up your terminal that's it otherwise your terminal is busy if you write Dash D you can do much stuff it keeps things in the background and the most important part is Dash B that means hey I want to free up a port and notice on this machine I have the port 3000 I want to bind it from the docker Port of 3000 now if the docker Port would be 5000 I would say hey 5000 we can mismatch the ports as well no big deal let's just say in our machine 3000 is busy I will just free up 3001 totally up to you how you want to do it I will talk about them later on but this is all the basics okay all right this is all good now what image you want to run I want to run this image which is this but remember this is not all that we have remember we said hey we want a specific version of the image which is 0.0.1 and then we say dot release and yes oops release and yes you have to provide the entirety of the name and versions and all of that and again by the way if you want to cheat a little bit go ahead into dashboard and look for this one you have to mention this tag 0.0.1.release in case you haven't mentioned this there's a tag latest already given to you so this is the basics and let's just hit a space and hit and enter now it gives us a really long string back which is a sha value again don't worry about this we just want to run the command Docker container LS now this time Docker says Hey There is a port ID remember they always gives you just a couple of words because hey who wants to write this pick and the name of the image is here and it says hey everything is running and it has also exposed the port for you now if I go back and try to see on the Local Host 3000 it still gives me hey node.js to verify that again I need to stop this so how can I stop this it's pretty easy all I have to say hey I want to stop a container so I can just go ahead and say Docker container stop and just mention eight to zero you can just mention two three uh letters of this because it will figure it out automatically that hey there is no two container which are of the same name so I better just stop this one Whatever that is yes it always takes a little bit time to stop that so don't panic out okay it says stop that now if I run this command again Docker container LS nothing is there go back up here and hit a Reload and you cannot reach the website okay this much is confirmed that I was able to create a rest API at least one endpoint and was able to containerize it and now I want to run that I can run that now the idea is that it should be public it should be available on my Docker Hub so that later on I can public pull it as well as anybody else who wants to can actually go ahead and pull this up let's go ahead and try this out so all we have to do is I want to say docker push this will you have already gone through with the docker login uh given the fact now I just want this name so I'll be just saying hey by the way I can actually just say Docker push and I can scroll a little bit and take out this name so I'll just copy this so that I don't make mistake and I'll just paste it here you can also write it in case you want to I'll just say hey hit enter and this will take my image and will push it on to the repository from where anybody can pull this off you might be in AWS Google cloud or anybody else you will be able to pull this off because this is public one there are other ways of storing these repositories or these images but we're not that advanced right now we're just going for that I think this is going to take just a few more minutes oh it's done I don't need to expedite it or do some magic video editing I'll just go into my profile and there we go I'm able to see node.js sometimes it takes a little bit time if I click on this hey there we go now this is available anybody can say Docker pull and just copy this command and can run this let's try this out let's try this out so what we're going to do is uh first let's go to the dashboard and we are going to go ahead and remove this image we can do that from command line as well but the Stocker desktop is like really easy I want to delete this forever uh the container that's using it so there's a container which is running it all right so we need to First we'll remove this later on but the whole idea is I'll walk you through that how to remove this and all of that right now if even if you try that uh that might not work because sometimes command line is much more powerful ah this is working uh there are a couple of more ways so let's just go ahead and delete this so right now we have no images on our system in the local but we have something on the remote so what we want to do now is we'll use the command line we'll use the command line and we'll just go up here copy this go back into the terminal at any point of time and this doesn't need to be from this location it can be from any location I'll just say Docker pull and this is going to pull the image this time not from the local but actually from the docker Hub and it says hey uh I need to give a specific version Docker pull and then I have to say colon and I have to say 0.0.1 [Music] Dot release and yes we can actually mention it latest and stuff then it will pull up easily and all of that we'll work on through that later on right now this is just the basics and notice here it is pulling it it already exists and now we have an image here so a newer image was downloaded and I can verify that with my Docker dashboard in the images but hey this image existed and this time this image was not something that we created this actually was brought in into our local from this remote repository this is really fantastic and now notice one important thing the person who is going to run this image on AWS or on gcp don't have to really worry about whether behind the scene there is a node.js or not really absolute nothing it could be behind the scene in Python I would have just say node.js and still the working functionality of how you manage it into kubernetes or your Cloud containers and all of that that remains same and that is the beauty of about it so that is the basics of behind the scene of an upcoming series that we are going to start very soon about the docker and the kubernetes and you're going to have so much of the fun so hit that subscribe because that series will come up very very soon based on how much you hit that subscribe and how much you share on this video let's go ahead and catch up in next video
Info
Channel: Hitesh Choudhary
Views: 56,748
Rating: undefined out of 5
Keywords: devops, cloud, Docker, kubernetes, containers, aws, gcp
Id: rr9cI4u1_88
Channel Id: undefined
Length: 163min 1sec (9781 seconds)
Published: Wed Nov 02 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.