Skip to content

Instantly share code, notes, and snippets.

@shanselman
Last active November 10, 2023 19:17
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shanselman/984c1792e16e9ca5fbc3bb55af461d64 to your computer and use it in GitHub Desktop.
Save shanselman/984c1792e16e9ca5fbc3bb55af461d64 to your computer and use it in GitHub Desktop.
Smarter ASP.NET Core Docker File
FROM microsoft/dotnet:2.0-sdk as builder
RUN mkdir -p /root/src/app/aspnetcoreapp
WORKDIR /root/src/app/aspnetcoreapp
#copy just the project file over
# this prevents additional extraneous restores
# and allows us to resuse the intermediate layer
# This only happens again if we change the csproj.
# This means WAY faster builds!
COPY aspnetcoreapp.csproj .
#Because we have a custom one
COPY nuget.config .
RUN dotnet restore ./aspnetcoreapp.csproj
COPY . .
RUN dotnet publish -c release -o published -r linux-arm
#Smaller - Best for apps with self-contained .NETs, as it doesn't include the runtime
FROM microsoft/dotnet:2.0.0-runtime-deps-stretch-arm32v7
#Bigger - Best for apps .NETs that aren't self-contained.
#FROM microsoft/dotnet:2.0.0-runtime-stretch-arm32v7
#FROM microsoft/dotnet:2.0.0-runtime-deps
#FROM microsoft/dotnet:2.0.0-runtime
WORKDIR /root/
COPY --from=builder /root/src/app/aspnetcoreapp/published .
ENV ASPNETCORE_URLS=http://+:5000
EXPOSE 5000/tcp
#CMD ["dotnet", "./aspnetcoreapp.dll"]
CMD ["./aspnetcoreapp"]
@emmysteven
Copy link

Thanks for sharing

@bplus0
Copy link

bplus0 commented Nov 10, 2023

Old post- sorry. Does this let you host a docker image on SmarterASP? I have a site up there, that i want to dockerize. Cant find any clear documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment