Skip to content

Instantly share code, notes, and snippets.

@ahmettek
Last active July 26, 2018 10:02
Show Gist options
  • Save ahmettek/2bdcfcd5af0905872fb8488e2721bb00 to your computer and use it in GitHub Desktop.
Save ahmettek/2bdcfcd5af0905872fb8488e2721bb00 to your computer and use it in GitHub Desktop.
Docker .Net Core
mkdir docker-sample
cd docker-sample
dotnet new MVC -n DotnetCoreWebApi
cd DotnetCoreWebApi\
dotnet restore
dotnet build
dotnet run
dir > DockerFile
Edit DockerFile
-------------------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", "DotnetCoreWebApi.dll"]
-------------------DOCKERFILE-------------------
docker build -t dotnetcorewebapi .
docker run -d -p 8080:80 --name sampleapp dotnetcorewebapi
localhost:8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment