Skip to content

ECS cannot pull the image

2 min read · main part only; folded sections are optional

After this you can answer: How do you debug a Fargate task that cannot pull its image?

Diagnostic scenario: ECS stops a new task with CannotPullContainerError. A related startup-error fragment is unable to pull secrets or registry auth under ResourceInitializationError. These are documented error categories, not a recorded MiniTickets outage.

ECS, the container scheduler, reports a failure before application startup. A missing manifest means the requested image is absent. An ECR access denial is Allowed: ECS uses the execution role during startup to pull images. A connection timeout is Reach. Registry authentication is separate from the app’s database Password.

flowchart TB
A[Stopped task reason] --> B{Image reference exists?}
B -->|no| C[Check repository and release tag]
B -->|yes| D{Access denied?}
D -->|yes| E[Check execution role]
D -->|timeout| F[Check public IP, route and egress]
D -->|image pulled| G[Check startup and architecture]

Rank within the matching error branch:

  1. Missing image: wrong repository/tag, failed publish, or retention removed a needed image.
  2. Timeout: missing public IP or internet route. MiniTickets has no NAT gateway or VPC endpoints.
  3. Denied: execution role lost its ECR policy. An explicit deny needs its own investigation.
  4. Pull succeeded, process fails: exec format error suggests an architecture mismatch; this is a startup failure, not a failed download.

ECS → Clusters → minitickets-dev → Tasks → filter Stopped → task: inspect its reason, task definition and networking. Compare its image URI with ECR → Repositories → Private → minitickets-dev-api → Images. IAM → Roles → minitickets-dev-api-execution-role → Permissions should list AmazonECSTaskExecutionRolePolicy.

Repair the failed branch: restore the exact image through publishing, correct the execution-role grant, or restore public-subnet networking. Keep ARM64 images aligned with runtimePlatform in infra/src/compute/task.ts → createApiTask.

CD checks image existence. Retention keeps the newest ten images tagged deployed-*, ranked by original push time; it does not protect every deployed image forever. Review that limit and the service’s public subnets and public IP together in infra/src/registry.ts → createRegistry and infra/src/compute/service.ts → createApiService.

Advanced: What each role and error proves

infra/src/compute/iam.ts → createIamRoles attaches the AWS managed execution policy. The running app’s task role has a different job; adding ECR permissions there cannot fix ECS startup. API and web tasks use public IPs to reach ECR, Secrets Manager and Logs while their security groups still restrict inbound traffic.

A successful CLI read uses your laptop identity and network. It proves image existence for that identity, not that the task’s execution role or network can pull it. Preserve the failed task’s reason and network metadata before ECS removes its record. AWS lists pull-error branches and startup initialization failures.

Read this book online: https://book.theversehub.in/