Push docker image to amazon ecs repository
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
When people say they want to push an image to an "ECS repository," they usually mean Amazon ECR, the container registry used by ECS tasks and services. The workflow is simple: build the image, create or identify the ECR repository, authenticate Docker against ECR, tag the image with the repository URI, and push it.
Build the Image and Create the Repository
First, build a local Docker image:
If the ECR repository does not exist yet, create it:
This returns repository details including the full repository URI, which looks like:
That URI is what Docker needs for tagging and pushing.
Authenticate Docker to Amazon ECR
Before pushing, Docker must log in to the registry:
This step is required because ECR is a private registry by default. If authentication fails, the push will fail even when the image and repository names are correct.
Make sure the AWS CLI is already configured with credentials and a role or user that has ECR push permissions. At minimum, the identity needs permission for authentication and image upload actions on the repository. Region mismatches are also common, so verify that the login region, repository region, and image URI all match.
Tag and Push the Image
Now tag the local image with the ECR repository URI:
Then push it:
After the push completes, the image is available for ECS task definitions and services.
It is common to use a versioned tag instead of only latest:
Versioned tags make deployments traceable and reduce confusion during rollbacks.
Verify the Push and Use It in ECS
You can verify that the image reached ECR:
Then reference that exact image tag in the ECS task definition:
ECS itself does not store images. It pulls them from ECR when tasks start. That is why pushing to the correct ECR repository is the actual deployment prerequisite.
If the task definition already exists, the next step is usually to register a new revision and update the ECS service so it starts tasks from the newly pushed image. The push is only the registry step, not the full deployment step.
Common Pitfalls
The biggest mistake is confusing ECS and ECR. ECS runs containers. ECR stores images. You do not push images to ECS directly.
Another common issue is tagging the image incorrectly. If the repository URI is wrong, Docker will either push to the wrong place or fail with a repository-not-found error.
Authentication problems are also frequent. If docker login was skipped or the AWS identity lacks ECR permissions, the push is rejected.
Finally, avoid relying only on the latest tag in real environments. Immutable version tags make debugging and rollback much easier.
Summary
- Build the Docker image locally first.
- Create or identify the target ECR repository.
- Authenticate Docker to ECR with
aws ecr get-login-password. - Tag the image with the full ECR repository URI and push it.
- Reference the pushed ECR image from your ECS task definition.
Related reading
- PWD is not set in ENV instruction in a Dockerfile
- Python service uses 100 of CPU on while loop with sleep inside docker container
- Rabbitmq connection refused from Docker container to local host
- RabbitMQ in Docker - user creation not persisted
- Push Messages from AWS Lambda to Kafka
- Python 3 Boto 3, AWS S3 Get object URL
- PyLint message logging-format-interpolation
- Python client euqivelent of kubectl rollout restart deployment

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.