Search code examples
amazon-ecs

does container gets recreated in ECS


A noob docker question I can't seem to find a definitive answer for.

A container is created from Dockerfile before it's spun up as an instance in ECS. How often does a container gets recreated from a Dockerfile in ECS?

The reason behind this question is as follow:

I'm inheriting a project where I see a pip install command inside a dockerfile (as opposed to inside requirements.txt) for several packages without a version number being specified.

pip install package_name

This to me looks like the latest version of package_name will be installed when the container was created from Dockerfile. I'm not sure how big of a problem this is as I'm not sure how often a container gets created from a Dockerfile. The project seems to need specific version of several packages not explicitly defined in the Dockerfile.

How often does a container gets recreated from a Dockerfile in ECS?


Solution

  • AWS Lambda will reuse a single container to handle multiple (non-concurrent) incoming requests. Of course ECS also uses a single container to handle multiple requests (even concurrent requests). ECS doesn't recreate an entire container for every HTTP request that comes in.

    The entire point of a scale-up event in ECS is to create more instances of a container, so container reuse in the context of a scale-up even makes no sense. There's no way for ECS to implement container reuse during scaling events or new instance creation events.


    To answer your updated question, commands in a Dockerfile run at build time, when the Docker image is being created. A pip install command in a Dockerfile should only run once, when you are building your Docker image. You mention a "container being created from a Dockerfile" but that terminology is wrong. An image is created from a Dockerfile. A container is created from an image.

    The ECS service does not create images. The ECS service only creates containers from existing images. You create the image yourself and push it to an image repository, such as Amazon ECR. You then configure ECS to pull that image from the repository when it needs to create a new container.