Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Big size of python image in Docker

Tags:

python

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?

like image 924
Lev Avatar asked Jun 25 '15 21:06

Lev


People also ask

What is the largest Docker image?

The largest uncompressed image is 498 GB which is a Ubuntu- based image. Figure 9 shows that the majority of uncom- pressed images in Docker Hub are small which aligns with the Docker philosophy to package software and distribute software in containers but include only its necessary dependencies.

Why is Docker image size so large?

Docker doesn't know what changes have happened inside a layer, only which files are affected. As such, this will cause Docker to create a new layer, replacing all those files (same content as /opt/jboss/wildfly/ but with with new ownership), adding hundreds of megabytes to image size.

Which Docker image is best for Python?

If you want the absolute latest bugfix version of Python, or a wide variety of versions, the official Docker Python image is your best bet. If you want the absolute latest system packages, you'll want Ubuntu 22.04; RedHat 9 is somewhat more conservative, for example including Python 3.9 rather than 3.10.


2 Answers

You can try the python:{version}-alpine version. It's much smaller:

>> docker image ls |grep python python    3.6-alpine     89.4 MB python    3.6            689 MB python    3.5            689 MB python    3.5.2          687 MB python    3.4            833 MB python    2.7            676 MB 

At time of writing it looks like the official image supports -alpine on all python versions.

https://hub.docker.com/_/python/

like image 142
toast38coza Avatar answered Sep 24 '22 04:09

toast38coza


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.

like image 24
Vlad Avatar answered Sep 22 '22 04:09

Vlad