简体   繁体   中英

Docker Image Size a Concern - Best Practice to create a base python image with ubuntu

Need : I want to create a minimal size python docker image on top of ubuntu14.04.

Problem : Ubuntu docker 14.04 image has 188MB size. On creating image with below Dockerfile, the image size becomes 486MB. Which is too much for such a small addition. I understand the less the number of instruction the lesser will be the size of the image. So I have kept it minimal.

What am I doing wrong?? and what is the best way to create a light dockerimage for python.

FROM ubuntu:14.04
RUN apt-get update && apt-get install -y -q curl \
build-essential \
python-dev \
python-pip \
vim \
wget && \
apt-get autoremove -y && \
apt-get clean && \
apt-get autoclean && \
echo -n > /var/lib/apt/extended_states && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /usr/share/man/?? && \
rm -rf /usr/share/man/??_*

There is no perfect answer here.

Using Ubuntu as a base image is a fine place to start, especially for legacy applications which expect to be deployed into an environment that needs to emulate a virtual machine. I would advise not letting this drive all your decision making, because containers are not virtual machines. They all share the kernel of the host machine. As @RobKielty states "Linux is Linux".

Fact is if your application has very few dependencies (for example go programs) then the extra size of the base image is simply redundancy. The use of alternative base images like Alpine is driven by a desire for faster downloads, but it also has security benefits too. It eliminates unused packages that would otherwise need to be patched. However... it's not a free lunch because using Alpine means more effort installing dependencies (that would already exist in a larger image like Ubuntu)

In conclusion I would refer you to the community python image. If you look carefully there are several available image tags, using python built on top of a variety of base images. Might save you a lot of effort.

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

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM