dotnet / dotnet-docker-nightly

This repository has moved to the nightly branch of dotnet/dotnet-docker.
https://github.com/dotnet/dotnet-docker/tree/nightly
MIT License
35 stars 30 forks source link

Reduce the number of layers in the Alpine runtime images #499

Closed MichaelSimons closed 6 years ago

MichaelSimons commented 6 years ago
FROM microsoft/dotnet-nightly:2.1-runtime-deps-alpine

# Install .NET Core
ENV DOTNET_VERSION 2.1.0-preview1-25919-02
ENV DOTNET_DOWNLOAD_URL https://dotnetcli.blob.core.windows.net/dotnet/Runtime/$DOTNET_VERSION/dotnet-runtime-$DOTNET_VERSION-alpine.3.6-x64.tar.gz
ENV DOTNET_DOWNLOAD_SHA 7a8b081c890226ba7220c654dc833752f837171c2fe449367d24c2980db3a809012478a67423fd46264e5d2f0389a6890077f8dd25a1fc4aeecb25deb84d72a4

RUN apk add --no-cache --virtual .build-deps \
        openssl \
    && wget -O dotnet.tar.gz $DOTNET_DOWNLOAD_URL \
    && echo "$DOTNET_DOWNLOAD_SHA  dotnet.tar.gz" | sha512sum -c - \
    && mkdir -p /usr/share/dotnet \
    && tar -C /usr/share/dotnet -xzf dotnet.tar.gz \
    && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
    && rm dotnet.tar.gz \
    && apk del .build-deps

The three ENV instructions are not necessary. The various official Docker images are not consistent on this pattern - some have it and others don't. Since the purpose of supporting Alpine is to have an efficient and slime image, IMO we should remove the URL and SHA layers. Their value is limited. I believe there is value in preserving the DOTNET_VERSION as this easily identifies the version of the primary component. Seeing this called out in the Dockerfile and when viewing Docker image layers is useful.

If this change is made, it should be used across all new Dockerfiles going forward in order to have consistency. Additionally, the update-dependency tool will need to be updated accordingly.

richlander commented 6 years ago

Makes sense to me.