What is Dockerfile | How to create and build Dockerfile | Dockerfile Basic Commands

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Applause] hello and welcome to this session on docker file this is going to be a very easy and interesting session on docker file and we will go very basic step-by-step and learn what is a docker file how to create a docker file how to build images from docker file and then we will also run these images to create containers and we will look at all the basic events and some tips with docker file so let's get started and docker file is a simple text file with instructions to build our image so you can see so docker file is a simple text file where we give some instructions to build an image and when we do docker build for this talk of file image gets created so until now we have been getting our images from docker hub so you can see here we have a lot of images in the docker hub repository and until now we have just pulled any of these existing images but if you want to create your own image you can use a taco file so docker file is basically automation of docker image creation and there are some basic instructions that you use in the docker file so let's go step by step and step one is we have to create a file named docker file so by default when you run the docker build commands docker searches for a file named docker file however it is not compulsory you can also give some different name and then you can tell the docker that this particular file is a local file but for now we will go with docker file so what I'm going to do is I will create a new folder and a file and if you are on Mac or Windows you can do that physically you can create a folder and a new file named docker file without any extension but for the benefit of people who are following this on linux and a command line operating system i will do this from the command line itself so I'm going to terminal and I will go to my desktop and here I will create a folder called docker files and I will go inside this folder and I will create a file called docker file now take care I am NOT giving any extension here I am just saying docker file and here it is and now I will go and edit this docker file so I am here in vim editor i will press i on my keyboard to go inside the insert mode and the very first instruction that a docker file starts with is from and you have to give a base image so for example if i want to get a base image from ubuntu i will say from ubuntu and of course you can use comments for example you can use hash get in this image which is open to now ideally we always use some base image or just in case you do not want to use any base image you can also say from scratch so if you go to docker hub there is another image called scratch and this is basically a empty image so if i go to the details you can see this is an empty image which is used for building images from scratch so you can say from scratch if you want to build or completely an image and then add to it but as of now i will say from ubuntu and then the other instruction is you have to give a min you know now this is optional but you its best practice that you give min dinner of this image so that it is very easy to find out who is the maintainer and you can give your name and email as well and if you want you can just give the email as well without giving the name but i am giving the entire thing and then let's say I want to run something so I will say run so it's an open - I can say apt-get update so I want to run this command on the image and if you want to run something on the command line during container creation you can give this CMD and inside square brackets I will say Iko and I'm saying hello world from my first docker image okay now the difference between run and CMD is run gets executed during the building of the image however the command that you get give inside CMD gets executed only when you create a container out of the image so this is done I will press escape on my keyboard and then I will press : the blue q and exclamation mark to exit and I am out so I can again go and see the contents of my docker file and here it is from open to I am giving the maintainer I am running a command and a CMD command okay so let me clear this and of course you can see here this is the folder and this is the file we created and here it is our file is here with all these instructions so now what we have to do is we have to now build the image so here are the commands you can use docker build so you can say docker build and you have to give the location of your docker file so either you can give the absolute location for example I can say users I can go to my desktop and the location or the folder where my docker file is or if you are already on that location for example I am already inside docker files location on my command line so I can say docker build and a dot so that means the docker file is present inside this folder itself we are we are running our command from now this command will create your image however you can also use the minus T flag for tagging your images so I can give a name to my image so I say this is my image 1 and : I can give some tag so if you want to give a tag and a name you can use this so this is my name my image 1 and the tag 1.0 so it will be easy to find out this image later on and I will just run this and you can see it is running step one from Ubuntu so it will get the Ubuntu image it did not find it locally so it is pulling from the docker hub library and it is now extracting and then you can see step two which is maintainer step three is done apt-get update and it is running all this command in the image and then step four is CMD and it is saying successfully built and we have got the image ID as well here is the image ID and you can see the act number is here so let me clear my terminal and if I say docker images you can see my image one the tag is 1.0 this is the image ID and this was created 31 seconds ago okay and we have also got a bun too because in our image we have first pulled open - image so now we have open - as well on our system now to run this image I will say docker run I can give the image name or the image ID let me give my image name my image 1 okay I think it will take our image ID so let me say docker run and the image ID here and yes you can say it is saying hello world from my first docker image this is what we have put in our docker file here and you can see this is now getting printed here so our image is created successfully and we are able to run it to create a container as well so let me write down the steps here step 2 is add instructions in docker file step 3 is build docker file to create image and step 4 is run image 2 create container okay also I will show you this useful link so here is one link where you can get some information about docker file and here actually you can get most of the commands so these are the instructions that we use in a docker file so you can get it from here also one very useful reference will be if you go to if you search for docker file on google the very first reference you will get is docker file reference from docker and here on this web page you will get everything about docker file I will copy this in the notes itself and all these nodes will be available with this video so I hope this very quick session on docker file was very useful for you I will meet you in the next episode of docker thank you for watching [Music] you
Info
Channel: Automation Step by Step
Views: 351,516
Rating: 4.8895321 out of 5
Keywords: what is dockerfile, how to create dockerfile, how to build image from dockerfile, dockerfile basic commands, dockerfile beginners tutorials
Id: LQjaJINkQXY
Channel Id: undefined
Length: 10min 9sec (609 seconds)
Published: Sun Jul 08 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.