Dockerize a .NET Core application - Avinashlikes/Wiki GitHub Wiki
Create a Dockerfile for an ASP.NET Core application
Step 1 : Create a
Dockerfilein your project folder.
Step 2 : Add the text below to your Dockerfile
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app
# 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:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
Step 3 : To make your build context as small as possible add a .dockerignore file to your project folder and copy the following into it.
bin\
obj\
Step 4 : Build and run the Docker image. Open a command prompt and navigate to your project folder.Use the following commands to build and run your Docker image:
$ docker build -t aspnetapp .
$ docker run -d -p 8080:80 --name myapp aspnetapp