Docker image different size when pushed to ECR than locally

That could be due to how docker client acts before it pushes the image to ECR as documented:

Beginning with Docker version 1.9, the Docker client compresses image layers before pushing them to a V2 Docker registry. The output of the docker images command shows the uncompressed image size, so it may return a larger image size than the image sizes shown in the AWS Management Console.

So when you pull an image you will notice that the image layers go through three stages:

  • Downloading
  • Extraction
  • Completion

Regarding this command: python /usr/local/src/app/app.py are executing it while you inside /usr/local/src/app/ ? You might need to ensure this first also have you checked the command inside the container using the image before you push it as the error seems to be code related more than a docker issue


We can read the following in the the AWS ECR documentation:

Note

Beginning with Docker version 1.9, the Docker client compresses image layers before pushing them to a V2 Docker registry. The output of the docker images command shows the uncompressed image size, so it may return a larger image size than the image sizes shown in the AWS Management Console.

I suspect you'd get the sizes you expect, would you use the CLI (docker images) instead of the ECR web console.