Search code examples
amazon-ecs

Pulling public images from Dockerhub in ECS Fargate


When I configure my taskdefintion on my ECS Fargate cluster to pull nginx:latest it fails with

STOPPED (CannotPullContainerError: Error response from daemon)

I fail to understand what to put into the task definition field "image".

It says there "repository-url/image:tag" but apparently it's not "nginx:latest" if I want to pull the public nginx image from dockerhub. What's the repository-url of dockerhub?


Solution

  • In ECS FARGATE/EC2 when we will specify the image we can directly specify any image name which we are able to pull it via docker command.

    For example if we are able to pull the latest NGINX image with command docker pull nginx where if we will not specify any tag then it will pull latest image. This is the same thing in ECS so either we can specify the nginx or nginx:latest both will work. That means image name you have provided is correct.

    The reason why are we seeing this error is not related to image but it might be related to the network where container running in FARGATE is not able to pull the Image.

    We have to keep in mind that FARGATE always uses the AWS VPC network mode which means there are two way to run the task in FARGATE:

    1. If we are trying to run the task in public subnet then Auto-assign Public IP must be enabled and we have to make sure that public subnet route table has IGW or any other gateway which will give proper internet connectivity which will allow the container to pull the image from public docker repo.

    2. If we are trying to run the task in private subnet then Auto-assign Public IP must be disabled and we have to make sure that private subnet route table has NAT gateway which will allow the container to pull the image from public docker repo.

    [1] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-configure-network.html