Last active
July 26, 2018 10:02
-
-
Save ahmettek/2bdcfcd5af0905872fb8488e2721bb00 to your computer and use it in GitHub Desktop.
Docker .Net Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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