Skip to content
Latchkey

Docker Push to ECR "repository does not exist" - Create the Repo First

Amazon ECR rejected the push because the target repository does not exist. Unlike some registries, ECR does not create repositories on first push unless you explicitly enable it, so the repo must exist beforehand.

What this error means

A docker push <acct>.dkr.ecr.<region>.amazonaws.com/<repo>:<tag> fails with name unknown: The repository with name "api" does not exist in the registry. Login succeeded; the repository is just not there yet.

docker push output
name unknown: The repository with name 'api' does not exist in the registry
with id '123456789012'

Diagnose it: separate auth from naming from rate limits

Registry errors look alike and have unrelated causes. Work out which of the three you have before changing credentials, because a malformed image reference produces an error that reads like an authentication failure.

Terminal
# 1. is the reference even valid? (lowercase, no spaces, valid tag)
docker image inspect "$IMAGE" 2>&1 | head -2

# 2. are you authenticated to the right registry?
cat ~/.docker/config.json | grep -o '"[^"]*\.[^"]*"' | head

# 3. are you rate limited? (Docker Hub anonymous pulls)
curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimit-preview/test:pull" \
  | grep -o '"token"' >/dev/null && echo "token ok"

Common causes

The ECR repository was never created

ECR requires the repository to exist before a push. A first deploy of a new service hits this until the repo is created via console, CLI, or Terraform.

Wrong region or account in the registry URL

A repository that exists in one region/account is "not found" when the push targets a different region or account id.

How to fix it

Create the ECR repository before pushing

Create it with the CLI (or Terraform) in the correct region, then push.

Terminal
aws ecr create-repository --repository-name api --region us-east-1
docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/api:1.4.2

Verify the registry URL’s region and account

Confirm the account id and region in the image reference match where the repo lives.

Terminal
aws ecr describe-repositories --repository-names api --region us-east-1

Authenticate in the job, not in the image

.github/workflows/ci.yml
- uses: docker/login-action@v3
  with:
    registry: ghcr.io
    username: ${{ github.actor }}
    password: ${{ secrets.GITHUB_TOKEN }}

# GHCR needs this on the job or the push is rejected as unauthorised
permissions:
  contents: read
  packages: write

How to prevent it

  • Create ECR repositories as part of infrastructure provisioning.
  • Keep the account id and region in the registry URL consistent with the repo.
  • Fail the pipeline early if the target ECR repo is missing.

Frequently asked questions

What causes Docker push to ECR "repository does not exist"?
There are 2 common causes: the ecr repository was never created and wrong region or account in the registry url. ECR requires the repository to exist before a push.
How do I fix Docker push to ECR "repository does not exist"?
There are 2 fixes depending on which cause you have: create the ecr repository before pushing and verify the registry url’s region and account. Work through them in order, since the first is the most common.
What does Docker push to ECR "repository does not exist" actually mean?
A docker push <acct>.dkr.ecr.<region>.amazonaws.com/<repo>:<tag> fails with name unknown: The repository with name "api" does not exist in the registry.
How do I stop Docker push to ECR "repository does not exist" happening again?
Create ECR repositories as part of infrastructure provisioning. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

This is a registry failure, not a bug in your code. Latchkey detects, repairs, and retries it for you. Start free → 30-day trial · No credit card