Skip to content

Instantly share code, notes, and snippets.

@ahmedig
Last active October 22, 2020 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedig/80c0bef6e8c200743bfdb7ad6f46eda4 to your computer and use it in GitHub Desktop.
Save ahmedig/80c0bef6e8c200743bfdb7ad6f46eda4 to your computer and use it in GitHub Desktop.
Docker file for a dotnet new react project
# Pull down an image from Docker Hub that includes the .NET core SDK:
# https://hub.docker.com/_/microsoft-dotnet-core-sdk
# This is so we have all the tools necessary to compile the app.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
# Fetch and install Node 10. Make sure to include the --yes parameter
# to automatically accept prompts during install, or it'll fail.
RUN curl --silent --location https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install --yes nodejs
# Copy the source from your machine onto the container.
WORKDIR /src
COPY . .
# Install dependencies.
# https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-restore?tabs=netcore2x
RUN dotnet restore "./azurediy.csproj"
# Compile, then pack the compiled app and dependencies into a deployable unit.
# https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish?tabs=netcore21
RUN dotnet publish "azurediy.csproj" -c Release -o /app/publish
# Pull down an image from Docker Hub that includes only the ASP.NET core runtime:
# https://hub.docker.com/_/microsoft-dotnet-core-aspnet/
# We don't need the SDK anymore, so this will produce a lighter-weight image
# that can still run the app.
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim
# Expose port 80 to your local machine so you can access the app.
EXPOSE 80
# Copy the published app to this new runtime-only container.
COPY --from=build /app/publish .
# To run the app, run `dotnet azurediy.dll`, which we just copied over.
ENTRYPOINT ["dotnet", "azurediy.dll"]
@ahmedig
Copy link
Author

ahmedig commented Oct 9, 2020

  • You need to replace "my-new-app" with the name of your project

  • Put this file in the root of the folder

Run:

docker build -t my-new-app .
docker run -p 80:80 my-new-app:latest

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