Through AWS CLI push docker image to ECR.
Disclaimer: Encountered to various silly errors but it only helped to think better. Moreover dont hop around doubts/topics and fall into loop, stick to one, solve it and if it is consuming unneccessary time write down the problem statement keep it aside and move on. When the fantastic brain is rechharged begin asking in community channels try talking it out with yourself/someone to have better analysis.
Happy Learning :)
aws ecr create-repository --repository-name <repo_name> --region <region> --profile <profile_name>
Building docker image
I have simple java application that says
Hello, world!As known Dockerfile is written to dockerize it.
-fused to point my Dockerfile where it is located through path provided.
-tto tag the image with image name provided.
docker build -f ./Dockerfile -t <image_name> .
Check if image is created with correct tag
docker images --filter reference=<image_name>
Tagging the image with repositoryuri provide while creating a repo.
Without being tagged by repositoryuri it wont be able to push push into desired repo created.
docker tag <image_name> <repository_uri>/<repo_name>
Command to get the docker login authentication for your ECR registry.
Edit the ecr_login_pass.txt by keeping just the auth token and removing the rest. Why am I doing this just to avoide clumsyness on my terminal and prevent the password from ending up in the shell’s history, or log-files. Try cheking in shell history and logfiles.
But this doesn't solve the issue of
WARNING! Your password will be stored unencrypted in ~/.docker/config.json.
which I have covered in post - [docker credential store - ECR](https://ashwiniag.com/ docker-credential-store-ecr/)
aws ecr get-login --no-include-email --region <region> --profile <profile_name> > ecr_login_pass.txt
Provide the endpont and input the pass from the text file created.
why endpoint? because when we run
docker loginby default it is pointing to docker hub repo which in our case we dont want that !
cat ecr_login_pass.txt | docker login --username AWS --password-stdin <your_aws_ECR_account_url>
Push docker image to ECR and play around little bit with other comands.
docker push <your_aws_ECR_account_url>/<repo_name>
aws ecr delete-repository --repository-name <repo_name> --region <region> --force
docker logout <your_aws_ECR_account_url>
Github link will be posted shortly