Docker Image Size a Concern - Best Practice to create a base python image with ubuntu
<p><strong>Need</strong>: I want to create a minimal size python docker image on top of ubuntu14.04. </p>

<p><strong>Problem</strong>: 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.</p>

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

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

<p>There is no perfect answer here.</p>

<p>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".</p>

<p>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)</p>

<p>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.</p>

<p><a href="https://hub.docker.com/_/python/" rel="nofollow">https://hub.docker.com/_/python/</a></p>

<p>Hope this helps.</p>

python image ubuntu docker