From ab4b993644e657fbe43a5da94bb1876f3cc3c33a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 27 May 2017 17:35:53 -0700 Subject: [PATCH] Break into build stages - Saves 10MB in space --- Dockerfile.alpine | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Dockerfile.alpine b/Dockerfile.alpine index b7443f0..66fe20f 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,25 +1,36 @@ -FROM nginx:1.13.0-alpine -MAINTAINER Jason Wilder mail@jasonwilder.com +# Build stages +FROM alpine:3.5 AS build-env + +ENV DOCKER_GEN_VERSION 0.7.3 # Install wget and install/updates certificates -RUN apk add --no-cache --virtual .run-deps \ - ca-certificates bash wget \ +RUN apk add --no-cache --virtual .build-deps \ + ca-certificates wget \ && update-ca-certificates -# Configure Nginx and apply fix for very long server names -RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ - && sed -i 's/^http {/&\n server_names_hash_bucket_size 128;/g' /etc/nginx/nginx.conf - # Install Forego ADD https://github.com/jwilder/forego/releases/download/v0.16.1/forego /usr/local/bin/forego RUN chmod u+x /usr/local/bin/forego -ENV DOCKER_GEN_VERSION 0.7.3 - +# Clone and install Docker-gen RUN wget --quiet https://github.com/jwilder/docker-gen/releases/download/$DOCKER_GEN_VERSION/docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz \ && tar -C /usr/local/bin -xvzf docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz \ && rm /docker-gen-alpine-linux-amd64-$DOCKER_GEN_VERSION.tar.gz +# Final Stage +FROM nginx:1.13.0-alpine +MAINTAINER Jason Wilder mail@jasonwilder.com + +# Configure Nginx and apply fix for very long server names +RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ + && sed -i 's/^http {/&\n server_names_hash_bucket_size 128;/g' /etc/nginx/nginx.conf + +# Install bash +RUN apk add --no-cache --virtual .run-deps \ + bash + +COPY --from=build-env /usr/local/bin/forego /usr/local/bin +COPY --from=build-env /usr/local/bin/docker-gen /usr/local/bin COPY . /app/ WORKDIR /app/