What is Docker? Docker File, Docker Image & Docker Container

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
when your colleagues are having a conversation about Docker do you just nod along hoping that they don't ask you something about it well if the answer is yes this video is specifically for you hello world my name is monus and today we will talk about Docker at the end of this video you will be able to clearly understand what Docker is and why is it needed we will also talk about Docker file Docker images Docker containers and how are they different from each other and we will do all of this with some really cool code examples which you can find in the link in the description so without further Ado let's get started a long time ago before anyone even knew the word Docker the development in the software companies used to happen in a very different way let's say that you were building a web application in Java in order to start development on your computer you first need to set up the application on your personal computer so that you can work on it this involved a lot of steps like installing Java installing web servers installing libraries installing database insert data into the database download the code and copy some configuration files in 10 different mysterious locations on your computer and after doing all of this your application still won't start and then you would ask a senior developer who has been in the company since before the time of the pyramids who adds that one line of code to the configuration file and voila everything works now all these steps need to be very well documented so that the new developers or a person coming back from their honeymoon could update their computers to make everything run even if one small configuration is missed it could get problematic for anyone and let's face it the guy who has been in the company since 3000 BC may leave at any time this is also a bit of a trouble when different developers have different computers and operating systems for example most of the people use Mac and Linux while the new guy has sworn to use Windows for his entire life on a bit of a serious note local machines are still fine even if something is not running 100% we can always find ways to tweak it because it is our computer and we have full access but things get really tricky when we want to make an application Live we still need to follow all those steps to make our application run on an external server and host it on the internet well this was a cause for concern in order to solve these problems Docker came into the picture it came up with the idea of separating your infrastructure and your application your application is simply the apis business logic and the underlying code to support this simp simply put it's just a bunch of code and some libraries and on the other hand your infrastructure is a bunch of things like a physical computer wher everything will run your database installed Software System configuration environment variables and these kind of things all of the manual steps that we discussed before were basically to set up the infrastructure now Docker allows all of these steps to be managed automatically instead of a person following a sequence of steps manually which basically sets up your infrastructure not only that Docker is also able to build your application code deploy it on the infrastructure and even run it and all of this happens in a very platform independent way so that the same infrastructure commands can run on different operating systems like Linux Mac and windows so let's see how this is done if we try to understand the core of programming in general the code that we write is just a set of instructions given to the computer similarly the steps for setting up infrastructure can also be written as instructions but the question is where do we write those instructions and how do we run them Docker allows us to write these instructions in a specific format called a Docker file just like you have Syntax for Java python C++ to provide instructions to your computer Docker file also has its own syntax the difference is in programming languages you automate the business logic and in the docker file you automate infrastructure commands on similar lines just like you need Java or python environment installed on your computer to run the Java or python code you need to have a Docker environment installed on your computer to run the docker file which contains your infrastructure commands now let's imagine that we have a very basic application with a few HTML pages and these HTML pages are in a git repository our goal is to Simply host these HTML pages on our local computer which doesn't have any software installed on it except for two things one is the git client so that we can clone the repository and second is the docker desktop so that we can run the docker infrastructure commands so let's clone our repository our repository looks something like this a bunch of HTML Pages a CSS and a Docker file to contain the infrastructure commands now in order to host these files on our computer we need to follow some steps first we need to install a web server like engine X or Apache so let's go with enginex next we need to copy our HTML files into an enginex directory from where engine X hosts it according to the enginex documentation that directory is this now we need to start the application so far it sounds clear now let's try to see how we can automate these instructions using our Docker file the first line in our Docker file signifies what environment we would like to use in our application it is prefixed with the word from followed by the name of the image that we would like to use for our application at this moment you can consider an image as a lightweight version of Linux with enginex installed on it along with some other software and security packages to make everything work nicely a lot of organizations and open source communities maintain different images for Java python C++ postrace database and such these are pretty basic but stable images which provide an environment for you to run your commands all these images are present on hub. do.com so when we write something like from enginex in our Docker file then there must be an image named enginex on the docker Hub now that we have got our environment sorted we need to copy our HTML and CSS to the enginex directory so that it can read it enginex specifies this directory in the documentation so whatever goes in this directory is served by enginex once this is done we have to create our own image out of this Docker file to do that we can run this command in this command after the dock build we have a few parameters so let's try to understand them a little bit the first parameter is prefixed with hyphen f followed by the name of the docker file in our case the name of the docker file is app. Docker file you can name it anything with the extension Docker file next parameter is hyphen T followed by our very own custom image name which has all these files that we copied in our case we would name it Docker _ engin xor image and finally we specify the path this specifies where to find our files and directories for example in our app. doer file we ask Docker to copy all HTML and CSS files to the engine X location path is the place where the docker is expected to find these files since this command was executed from the directory where the files were present dot was specified to denote the current directory now when this command is executed the docker system will try to find the lat version of the engine X image and loaded onto our computer if this process is successful it will execute the remaining commands to copy the HTML and CSS to the enginex directory when all of these commands are successfully executed a new image will be created which is based on the engine X image but has some extra stuff that we needed so in a way it becomes our very own custom image and resides on our computer this can even be checked by executing the docker list command this should list the new image with the name Docker engin xor image as we specified in our previous command to summarize all of this at first we had a Docker file which contained some instructions and we used the docker built command to convert these instructions into an actual image at this point we have got ourselves a very well-defined image which contains everything we need including our code to run our app and now we also know the difference between a Docker file and a Docker image now the next step is to run this image with the docker run command a running version of an image is called a container so here is a basic command to spawn a container based on an image in this Docker run command we have specified two parameters the first parameter is prefixed with hyphen P which refers to Port Now enginex by default runs on port number 80 but this port resides within the docker container and is accessible only within the docker container it means that if you were to access this application from your browser which is outside of the docker this port will not be accessible therefore we need to forward the traffic from our computer port number 80 to the docker's port number 80 so that the docker can pass our request to enginex which in turn can process our requests now all of this can be made possible by using the hyphen P parameter the left Port is the port of the host system that is your computer and the port on the right is the engine xort within Docker this will allow the traffic from the host system to flow into the docker's engine X next parameter is the name of the image that we built before using the docker build command so that Docker knows which image it needs to run because you may have a lot of other images in your system as well so let's run this command and then try to access our application through the curl command here here we can clearly see the page code along with server header which tells us that this page is indeed coming from enginex similarly we can access the enginex app also from the browser to see the response if we go to our Docker desktop and select containers on the left panel we should clearly be able to see our container running in Green in addition to this we can also see the image name and the forwarded ports to practice and play around with this setup you can download all of this code from my public repository link is down in the description finally to summarize all of this Docker is basically a technology which decouples the application code from infrastructure we write Docker file to write instructions on how to set up our infrastructure this is usually based on another image like Java python C++ or could be as simple as enginex these core images are maintained by different organizations and open source communities with our Docker files we use the images and customize them then we build these Docker files into new custom images the build process executes the commands within the docker file and in turn creates a new Custom Image which has everything we need to run our application this image resides on our computer next we simply run our image to see our application a running image is basically called a container and following the same lingo when the application is packed into one or more Docker containers this process is usually called called containerization now throughout this whole process the application developers never had to install engine X on their own system rather they can just write code change the HTML build a new image and run the container without worrying anything about the infrastructure even if there was any secret configuration it would be present in the docker file I hope that the fundamentals of Docker are clearer to you now but there are still some questions which are left unanswered this was a very basic applic that we made but how do we make more complex applications like applications with databases and messaging systems do we need multiple Docker images and containers and if yes then how will they interact with each other is there any difference between how Docker works on a local computer versus how it works on a live server hang tied for my next video on Docker in which I will answer all of these questions so that you have a complete overview on how Docker Works see you in the next video B done
Info
Channel: Monis Yousuf
Views: 3,498
Rating: undefined out of 5
Keywords: docker, software engineering, dockerfile
Id: k29FmUcihSA
Channel Id: undefined
Length: 12min 25sec (745 seconds)
Published: Thu Dec 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.