Docker image different size when pushed to ECR than locally
Asked Answered
R

2

19

I have a docker image that is 1.46GB on my local machine, but when this is pushed to AWS ECR (either via my local machine or via CicleCI deployment) it is only 537.05MB. I'm pretty new to Docker and to AWS, so any help in figuring out as to why this may be would be appreciated!

I have a feeling that it has not fully uploaded to ECR for whatever reason, as I am trying to use this container for a Batch job, but for some reason the same command which works when used locally does not work when used in the job definition. The command is simply python app.py, but I have also tried with absolute path python /usr/local/src/app/app.py, both of which result in [Errno 2] No such file or directory.

Commands used in my Makefile deployment are as below:

docker build --force-rm=true -t $(EXTRACTOR_IMAGE_NAME) ./extractor
docker tag $(EXTRACTOR_IMAGE_NAME) $(EXTRACTOR_ECR_IMAGE_NAME)
$(shell aws ecr get-login --no-include-email)
docker push ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/$(EXTRACTOR_ECR_REPO)

Edit 1: I think this might be to do with the size of the base image, which is python:2.7 in this case. The base image is 914MB, plus the size of my ECR image 537.05MB = 1451.05MB, i.e. approx 1.46GB. Still not sure what the issue is with the Batch command though...

Edit 2: I've been mounting code into my container using a volume, which is why this has been working locally. At build time I've forgotten to copy the code into the container, which I assume is the only reason why this is not working in Batch!

Rapids answered 10/3, 2019 at 12:31 Comment(2)
Is it zipped?Adallard
I'm not sure if ECR stores images as zipped... I'll try zipping locally to check what the size is.Rapids
B
31

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

Bumper answered 10/3, 2019 at 12:55 Comment(3)
The command in my Dockerfile is CMD ["python", "app.py"] which is run after WORKDIR /usr/local/src/app. I will update the OP with the Dockerfile. If I docker run my container on my local machine without overriding the command from the Dockerfile then it does work as expected.Rapids
I've just checked my Dockerfile and it seems I've been rather a silly boy. I've forgotten that in development I have been mounting my code in a volume, hence why it is working locally. I've forgotten to COPY my code into the container at build and push time, so it seems that this is the source of my problems! :PRapids
Glad that you figured out the problem :'DBumper
C
6

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.

Calgary answered 10/3, 2019 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.