How to Create Docker image & push Image into Amazon ECR | How to setup Docker Registry in Amazon ECR

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello folks welcome back in this video we are going to learn how to set up an elastic container registry in aws and we will also learn how to create a docker image in our one of our to instance and then you know we are going to push the docker image into ecr so this is the use case right i have already project setup in github which already you know has a docker file so we have dockerized this particular application okay and then we have easy to instance up and running which already has docker installed what we are going to do is we are going to create a docker image in this instance okay and then we are going to push the docker image into amazon ecr right so that is what we are going to do so ecr is nothing but you know it's a fully managed docker container registry provided by aws for hosting our docker images right so you don't have to worry about uh hosting your container registry you know separately right they are going to take care of underlying infrastructure like scalability you know and high availability and whatnot okay so we don't have to worry about that and then you know wherever you are going to deploy your docker container uh you know it could be kubernetes or it could be amazon you know eks and whatnot ah you know those container organization platform can pull the image from amazon acr right so that is the use case okay awesome so let's get started so this is my website saydevops.com i have you know already provided the steps documented in this page i will be posting uh this link right below the url i mean the video url okay okay so what is so if you look at uh this you know diagram um you know i'm i already have ec2 instance setup okay which has docker installed i also have github you know where you know i have a project setup with the docker file as well along with the source code so what we are going to do we are going to check out from here and you know we are going to build the docker image in this ec2 instance which has docker installed okay and then i am going to uh tag the image and then i am going to push that image into amazon ecr right so easier is nothing but you know it's a managed docker uh registry for hosting a docker images so you don't have to worry about uh you know creating a private registry or something like that or you don't even have to worry about how to you know scale up underlying infrastructure and whatnot okay so they are gonna take care of it okay and then once you upload your docker image uh whichever the container organization platform you have you know kubernetes or you know swam or you know or you know aks and whatnot you know you can pull the image from here and then you know you would be able to deploy into your kubernetes cluster okay so this this is the use case this is what we are going to talk about right so we are going to build a docker image in this ec2 instance and then we are going to upload that image into amazon hcr okay so this is what we are going to do awesome so like i mentioned uh this is my you know ec2 instance which already has docker installed i have already connected to my ec2 instance here so this is the easy to instance this this has docker installed okay so what we are going to do first uh we are going to log into uh aws and then we are going to you know create a elastic container registry right so we are going to create a container registry right so let's do that so let me type ecr here so i'm going to go here elastic container registry i'm going to create a repository so click on create repository so give some name so i'm going to call this as my docker repo right so this is the repository name this is where we are going to host our docker images and then click on create repository awesome so we have successfully create uh you know creator and repository right so you can click on the repository name and when you click on view push commands so this is the one you know it is going to show you uh you know what are the commands you have to use in order to you know log in successfully into ecr and then how you can create a darker image how you can tag it and then you know how you can push that image into this you know repository okay so these are the commands awesome so click on close so we have successfully created this repository and then the next step is uh you know we have to go to our ec2 instance all right and then you know create uh you know docker image right but before that we have to ensure that you know we are able to successfully uh you know connect to the ccr right so how do you do that there are couple of ways uh you can you know connect to this ecr securely uh one of the ways is you know uh using the im role okay because we are already in aws right if you are already near ws you actually don't need to uh you know create you know access key and secret key right you can use the im role in order to access you know ecr okay and then the second way is you know using access key and secret key and you know this is only if you are you know outside the aws setup right let us say if you are using your local machine uh you want to connect to uh aws you can use access key and secret key okay but we are not going to do uh that right let's go ahead and then create an im rule okay so i'm gonna go to a services here and click on iim okay all right so click on roll here and click on create role okay and click on ec2 because you know what we have to do we have to create an am role and then assign that role to that easy to instance okay and we have to attach a policy to it okay so i'm going to show you how to do that so click on this one and then say next permission okay and in here what we have to do if you type ecr uh no sorry just type amazon elastic there you go type registry here that would be better yeah so we have to select this policy right so we have to give this policy so go and say next you don't have to give any tag so click on review and you have to give a role name right so i'm going to call this as docker ec2 you know ecr role so that is the role i'm going to give right okay and then say create role okay so we have successfully created this role so what we need to do we need to assign this im role to the ec2 instance right so let me uh go to ec2 and then click on this and we have to choose our ec2 instance which is nothing but this one and go to action and then see instant setting and then we have to attach that role right which is nothing but this one right and then click on apply so basically the e32 instance has full access to amazon ecr right so that is what we need to do and which we did right now okay so we are good to go on that so moving on to a next step so we did this right we created this im role and then attached to that ec2 instance okay and then we have to create or sorry we have to set up aws cli okay so let's go ahead and do that this is the command because you know we are going to access ecr using aws you know cli okay so once it is installed we are going to verify that okay awesome so we will successfully install that okay great and then the next step is you know we have to make sure that we are able to connect to uh you know acr right so we should be able to log in that first so how to do that if you remember uh we created uh the ec or i mean we created a you know docker registry right in ecr so let's go there and then click on this repository name and then click on view push commands and then you just have to select this one right so this should you know able to this command should be able to log into ecr ok so let me go ahead and then copy that okay and then enter awesome you see here so we were successfully able to log into ecr okay so we are good with that now we know we should be able to create a docker uh you know image right okay so this is the account id so basically the account id is nothing but this one right so which you can get it from ah here right so this is the account id right this is the account id right ok ok all right so if you see here you know so this is the repository okay so this is the repository okay so basically if you see the next step right we should be able to you know access our github right so if you see here i have already created a repository and i know this is a python based application i have already dockerized this application by creating a docker file right so if you look at this this is you know installing the python and then copying the source code right as well as the html file and then i know we are exposing port number for 5000 for the container and then this is the command to run the application right so this is this is a docker file right so this is where our source code is okay so all i have to do is ah check out this right and this is already a public repository so this is the command we are going to execute that so go ahead and do that okay see here now if i type ls minus al you know i'm able to clone that entire repository along with the source code and then you know docker file right so we are good to go right so we should be able to create a docker uh image right so what i'm going to do i'm going to build a docker image by executing this command okay so i'm going to give some name here right okay so that is the image name so right now it is in the process of building the docker image okay so the docker image has been built and you can quickly check that by executing this command docker images right so this is the image right and and we were able to build that okay so how we are going to push this image into ecr so we have to do what we have to do we have to tag that image right so we have to tag the image so how to tag it so this is the command we are going to use the docker tag command okay and then we are going to tag it right so this is the image name right so this is the image name okay and then how we are going to target based on your account id right so if you remember we have earlier uh you know created we were able to connect to it right so basically this is what you know we have to use right so what i'm going to say okay so i'm going to say docker tag okay my python latest right and then i'm going to do this and then what is our repository name right so we have to give our repository name right so if you remember we have created a repository as so basically yeah i mean this is the command we are going to give right okay okay and you can quickly see that okay see here so we were able to tag it you know per this you know repository see here right so this is our image name right okay so we tagged it successfully right okay so this is our image name right we already tagged it for this particular repository right so the next thing is you know now we should be able to push this docker image right so all we have to do is execute this command right because that is so we tagged it right so just go ahead and copy that okay so the image has been pushed ah what you can do you can verify that by closing this and click on here and click on the repository name wow you see here we were successfully able to push the image into ecr right so yeah so that's it guys you know that's how you can create image and then you know you would be able to push that image into ecr thank you for watching guys
Info
Channel: DevOps Coach
Views: 56,503
Rating: undefined out of 5
Keywords:
Id: D8ym8RP1yvo
Channel Id: undefined
Length: 16min 0sec (960 seconds)
Published: Wed Jul 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.