Why are Docker container images so large?

前端 未结 8 1909
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 17:32

I made a simple image through Dockerfile from Fedora (initially 320 MB).

Added Nano (this tiny editor of 1MB size), and the size of the image has risen to 530 MB. I\

相关标签:
8条回答
  • 2020-11-30 18:03

    The following helped me a lot:

    After removing unused packages (e.g. redis 1200 mb freed) inside my container, I have done the following:

    1. docker export [containerID] -o containername.tar
    2. docker import -m "commit message here" containername.tar imagename:tag

    The layers get flatten. The size of the new image will be smaller because I've removed packages from the container as stated above.

    This took a lot of time to understand this and that's why I've added my comment.

    0 讨论(0)
  • 2020-11-30 18:07

    Yes, those sizes are ridiculous, and I really have no idea why so few people notice that.

    I made an Ubuntu image that is actually minimal (unlike other so-called "minimal" images). It's called textlab/ubuntu-essential and has 60 MB.

    FROM textlab/ubuntu-essential
    RUN apt-get update && apt-get -y install nano
    

    The above image is 82 MB after installing nano.

    FROM textlab/ubuntu-essential
    RUN apt-get update && apt-get -y install nano git
    

    Git has many more prerequisites, so the image gets larger, about 192 MB. That's still less that the initial size of most images.

    You can also take a look at the script I wrote to make the minimal Ubuntu image for Docker. You can perhaps adapt it to Fedora, but I'm not sure how much you will be able to uninstall.

    0 讨论(0)
提交回复
热议问题