Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating from aspnetcore docker repos to dotnet #298

Open
glennc opened this Issue Mar 29, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@glennc
Copy link
Member

glennc commented Mar 29, 2018

Starting with .NET Core 2.1-preview2, we intend to migrate from using the microsoft/aspnetcore-build and microsoft/aspnetcore Docker repos to the microsoft/dotnet Docker repo. We will continue to ship patches and security fixes for the existing aspnetcore images but any new images for 2.1 and higher will be pushed to microsoft/dotnet.

Dockerfiles using microsoft/aspnetcore:<version> should change to microsoft/dotnet:<version>-aspnetcore-runtime.

Dockerfiles using microsoft/aspnetcore-build that do not require Node should just change to microsoft/dotnet:<version>-sdk.

Dockerfiles using Node from the microsoft/aspnetcore-build image will either need to install Node into their own image or use mult-stage builds as described in the Dockerfile examples at the end of this announcement.

The ASPNETCORE_URLS env var that allows ASP.NET Core apps to accept traffic from outside the container will be set in all the dotnet images, which was a common early stumbling block for people getting started with ASP.NET Core and Docker. PR is here

Why the merge?

For some time we have been seeing people search for and find the microsoft/dotnet images and never realise that there are aspnetcore ones. This could be problematic in the past as the dotnet images were not optimised for ASP.NET Core, making things a little harder or slower. But with changes in the way ASP.NET Core works in 2.1 it was going to be much more impactful, in that ASP.NET Core applications were not likely to run on the base dotnet image. Given that we also thought it made more sense to have a single repository for all images, as ASP.NET is just part of .NET, we are taking this opportunity to remove the potential source of confusion and wasted time for our customers.

Why no Node?

There are two main reasons for this:

  1. Multi-stage build now makes it easier to pull in the Node image for purely build concerns.
  2. The ASP.NET Core templates no longer have a hard dependency on Node.

For discussion and feedback on this decision you can go here: aspnet/aspnet-docker#403

Dockerfile examples

If you need Node then you will need to add it in your own Dockerfile, like this:

FROM microsoft/dotnet:2.1-sdk as build-env
WORKDIR /app
#setup node
ENV NODE_VERSION 8.9.4
ENV NODE_DOWNLOAD_SHA 21fb4690e349f82d708ae766def01d7fec1b085ce1f5ab30d9bda8ee126ca8fc

RUN curl -SL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz" --output nodejs.tar.gz \
    && echo "$NODE_DOWNLOAD_SHA nodejs.tar.gz" | sha256sum -c - \
    && tar -xzf "nodejs.tar.gz" -C /usr/local --strip-components=1 \
    && rm nodejs.tar.gz \
    && ln -s /usr/local/bin/node /usr/local/bin/nodejs

# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

# copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# build runtime image
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
#setup node, this is only needed if you use Node both at runtime and build time. Some people may only need the build part.
ENV NODE_VERSION 8.9.4
ENV NODE_DOWNLOAD_SHA 21fb4690e349f82d708ae766def01d7fec1b085ce1f5ab30d9bda8ee126ca8fc

RUN curl -SL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz" --output nodejs.tar.gz \
    && echo "$NODE_DOWNLOAD_SHA nodejs.tar.gz" | sha256sum -c - \
    && tar -xzf "nodejs.tar.gz" -C /usr/local --strip-components=1 \
    && rm nodejs.tar.gz \
    && ln -s /usr/local/bin/node /usr/local/bin/nodejs

COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

If you only need Node at build then you may also be able to take advantage of multi-stage build like the following:

FROM microsoft/dotnet:2.1-sdk as build-env
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore

FROM node as clientBuild
#Do npm restore and other Node stuff.

#Merge the contents of your .NET build env and your clientBuild and publish.
FROM build-env as publish
# copy everything else and build
COPY --from=clientBuild . .
RUN dotnet publish -c Release -o out

# build runtime image
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app

COPY --from=publish /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

For discussion and feedback on this decision you can go here: aspnet/aspnet-docker#403

@aspnet aspnet locked and limited conversation to collaborators Mar 29, 2018

@Eilon Eilon modified the milestones: 2.0.0-preview2, 2.1.0-preview2 Mar 29, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.