[docker] Multi-stage builds

Consider the following scenario: you are going to rolling update your cluster, and it turns out your network bandwidth is limited for some reason and size of built docker image is not small enough. What’s worse, every instance of cluster will need to pull the docker image before start-up…

Multi-stage builds feature is introduced in Docker Engine 17.05, which can avoid producing two or more Dockfiles. The major benefit is we can have smaller (only required binary) docker image. Here is an simple example to show how to archive it. The source code is on github.

Dockerfile:

 

After docker build, we can compare the docker image file size:

REPOSITORY TAG IMAGE ID CREATED SIZE
clsung/appdash                   latest              bf98d0e0f894        17 hours ago        15.5MB
<none>                           <none>              4c6d1097ad0c        17 hours ago        343MB

Ref:

Date
Categories
Tags
Permalink
Status

Published:May 14, 2017

docker golang

Bookmark the permalink

Post a comment or leave a trackback: Trackback URL


Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*
*