‫One thing that can come up in Amazon ECR is how
‫to use the CLI to pull and push images to Amazon ECR.
‫So first, there is a login command
‫and this login command is going to give you
‫docker credentials for your docker CLI.
‫So the idea is that you use the AWS ECR
‫get login password command line in the face
‫and I will demo it to you.
‫And then you pass the output of that command
‫into a docker login command,
‫which is going to allow docker,
‫your docker CLI on your computer to connect
‫to your private repository on AWS.
‫And once you have done that,
‫then you can run some basic docker commands
‫to pull and push images.
‫So to push an image, we just do docker push
‫and we specify the account ID and the region of Amazon AWS
‫as well as your image name.
‫And to do a pull well is the same with docker pull.
‫And if you cannot push or pull a docker image,
‫then that means that you don't have the right
‫IM permissions.
‫Now let me demo these cammands to you
‫so you understand what I'm talking about.
‫So in our test definition from before we were
‫running a image, okay
‫and this image was called nginexdemos/hello.
‫And to type this, you're going to land on hub.docker.com.
‫And so this is why when we downloaded this image
‫it was directly ending a up on ECS through this docker hub.
‫So actually our EC2 instance was pulling an
‫image from the docker hub.
‫But say we wanted to
‫host that image for reasons onto our private ECR repository.
‫Therefore we would go into Amazon ECR
‫and then we would create a private repository.
‫And then we would name it something,
‫for example, demostephane.
‫Okay, next you can see different options for Amazon ECR.
‫For example tag immutability
‫that prevents you to push the same tag twice,
‫or image scan to scan your images on push
‫to make sure they don't have any kind of security issues.
‫Although there is a deprecation of this feature,
‫and it's better to use registry level scan filters
‫which is called Amazon Inspector.
‫And finally, whether or not you want to encrypt
‫your Amazon ECR repository with KMS.
‫But I will just leave everything disabled
‫and I will go ahead and create my repository.
‫So you can see we have public and private repositories.
‫And the difference is that public repos
‫are going to allow anyone to pull our images.
‫Whereas private repos allow just us
‫with the right IM permissions to pull some images.
‫Okay so here we go.
‫We're going to click on this repo
‫and as we can see, we have 0 images.
‫So you can click on push commands
‫and these commands are going to be different
‫if you have Mac or Linux or Windows.
‫And so we're going to use the one for Mac and Linux,
‫but again, if you're on Windows
‫and you want to follow along, then just use these comments.
‫Okay?
‫So the first thing to check is
‫whether or not docker is enabled and running,
‫and you need to have docker running
‫on your computer and installed.
‫And I won't show you how to do this, but for me
‫it is running right now.
‫And if I do docker version
‫I have a recent version of docker.
‫Next thing to set up, obviously your CLI
‫and then you will be able to run this command.
‫So let's copy this command and I'm going to paste it in.
‫And then it says, login succeeded.
‫So if I did this command only on its own, okay.
‫If I did this get login password,
‫it's going to give me a password
‫that's going to be used
‫by my docker login command with the username AWS.
‫And so therefore this password is going to get
‫passed all the way into this command right here.
‫So I'm logged in and this is good.
‫And next, what I need to do is to build tag and push images.
‫So we don't have anything to build,
‫but what I'm going to do is pull this image
‫and then rename it.
‫So I'm going to do docker pull as well
‫as the nginexdemos/hello.
‫And it's going to pull the image for me.
‫So I already pulled it,
‫but for you it would go into a download.
‫And then you need to do what's called a docker tag command.
‫So you do docker tag
‫you paste this command,
‫you paste it in.
‫And so the first thing we're going to change.
‫So we're going to actually rename the first one.
‫So the first bits, and we're going to do docker tag
‫and we paste in nginexdemo/hello latest
‫into, well this thing, which is my repository name,
‫my image name
‫as well as my tag.
‫So lets press enter.
‫And that means that this image right here
‫has been also renamed to be like this.
‫Why? Well, because if you do docker push.
‫And then you paste in this whole image
‫then docker is smart enough to know
‫that it should be pushing into our Amazon ECR repository.
‫So let's try it out.
‫Let's press enter.
‫And as you can see, the image is being pushed.
‫And so it pushes data into AWS.
‫And now this is done.
‫And this worked because I was currently
‫and correctly authenticated with my ECR repository.
‫And if I wasn't
‫I would get an IM permission issue right here.
‫And so if we refresh this, as we can see
‫we see in my repository demostephane
‫the latest image for my image named demostephane
‫and you can click on it and use some information.
‫And now thanks to this image.
‫I could go ahead set up my own task definition
‫with this image.
‫And it would be pulling directly this image
‫from the ECR and not from the docker hub.
‫Okay. So I hope that was helpful.
‫I hope you like this lecture
‫and I will see you in the next lecture.