From 48a4ee0ad645322228f425c101e02840774e5790 Mon Sep 17 00:00:00 2001 From: Karsten Heymann Date: Wed, 10 Jul 2019 14:01:42 +0200 Subject: [PATCH] Update dockerfile to create 90% smaller image This change uses the 2.4-alpine base image variant and a two-stage docker build to reduce the size of the resulting image from 700 MB to around 70 MB with no obvious loss of functionality. --- Dockerfile | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 64def2e..22ddd18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,21 @@ -FROM ruby:2.4 +# Phase 1: Build the gem and all dependencies, needs C compiler +FROM ruby:2.4-alpine as builder -RUN gem install redis-stat +RUN apk add --no-cache build-base + +ENV GEM_HOME "/gems" + +RUN gem install -N redis-stat + +# Phase 2: Build the actual docker image, needs no C compiler -> much smaller image +FROM ruby:2.4-alpine + +RUN apk add --no-cache ncurses + +ENV GEM_HOME "/gems" +ENV PATH $GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH + +COPY --from=builder /gems /gems EXPOSE 63790 ENTRYPOINT ["redis-stat"]