tim tim - 1 month ago 19
Python Question

Big size of python image in Docker

I want to test my app with Docker. So, I have this in Dockerfile:

FROM python:3-onbuild
CMD [ "python", "./test.py" ]


test.py:

print(123)


Then I run:

docker build -t my_test_app .


So, I have one big image.
docker images
return:

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
python 3-onbuild b258eb0a5195 8 days ago 757 MB


Why is the file size so large?

Is that file size normal?

Answer

I just checked on my machine the standard ubuntu:trusty image is 188 MB and the image with all python stuff is 480MB. I see 800MB images quite often, those are usually ones that contain some meaningful application.

However, these images are based on our private images the official Docker library image seems much larger for some reason. They are aware of this fact and are trying to reduce it. Look at the discussion on the subject here

If you need a bit smaller image try this one 'rouge8/pythons' it is about 100MB smaller.

rouge8/pythons latest … 680.3 MB

Keep in mind, docker images are arranged as a hierarchical layer structure. So if you reuse the same underlying base image for many containers the size that each individual container adds is quite small. It will only be the difference between the base plus whatever you added into specific container.