1) Create a repository in the AWS Console
In the AWS Management Console search for “ECR” and choose Create repository (or go to Repositories → Create repository). During creation you can configure visibility, immutability, image scan on push, and KMS encryption.
Repository visibility cannot be changed after creation. Choose
Private or Public carefully before creating the repository.ecrdemo) appears in the list. It initially has no images until you push one.
2) Authenticate Docker to ECR
ECR authentication uses the AWS CLI to generate a short-lived Docker login token. Run the following command (example uses regionus-west-1 and account 841860927337):
- Install and configure the AWS CLI and run
aws configurewith credentials that have ECR permissions, or - If running on EC2/ECS/EKS, attach an IAM role with appropriate ECR permissions to the instance, task, or node (preferred for AWS-hosted compute).
If you see “Your password will be stored unencrypted in /home/…/.docker/config.json”, configure the Docker credential helper or the Amazon ECR credential helper to avoid storing plaintext credentials. See the Docker documentation and the Amazon ECR credential helper docs for setup instructions.
3) Build, tag, and push a Docker image to ECR
Replace the account ID, region, and repository name in these commands.docker push, Docker uploads each layer and prints a digest for the image:
4) Pull and run the image from ECR
To confirm another host can pull the image from ECR, remove the local ECR-tagged image and run a container using the full ECR URI. Docker will pull the image if it is not found locally.5) Repository naming and where to use the full image URI
Remember the full image name format used to push and pull from ECR:<aws-account-id>.dkr.ecr.<region>.amazonaws.com/<repository-name>:<tag>
Example:
841860927337.dkr.ecr.us-west-1.amazonaws.com/ecrdemo:latest
Use this full URI in:
- Docker CLI
- Amazon ECS task definitions
- Kubernetes manifests (EKS)
- Any other container orchestration platform that pulls from ECR
Quick reference table
Permissions and best practices
- Ensure any machine or service that pulls images has valid AWS credentials or an attached IAM role with ECR read permissions.
- For AWS-hosted compute (EC2, ECS, EKS), prefer using IAM roles with the minimum required ECR permissions rather than embedding long-lived access keys.
- Consider enabling image scan on push and using image tag immutability to improve security and traceability.
Useful links and references
- Amazon ECR documentation: https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html
- Docker credential helpers: https://docs.docker.com/engine/reference/commandline/login/#credentials-store
- Amazon ECR Credential Helper: https://github.com/awslabs/amazon-ecr-credential-helper