Docker .NET Example
Blog Post
.NET 6
Please check net6.0 branch.
.NET 7
Please check net7.0 branch.
License
MIT
Hello!
How are you? I hope all of you are stay safe and having a great day!
If you want to follow this step-by-step. Please install some tools that will be required here.
dotnet new webapi -o DockerNetExample
dotnet new sln
dotnet sln add DockerNetExample
Dockerfile
at the root, similar place with the .sln
file.
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine as build
WORKDIR /app
COPY . .
RUN dotnet restore
RUN dotnet publish -o /app/published-app
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine as runtime
WORKDIR /app
COPY --from=build /app/published-app /app
ENTRYPOINT [ "dotnet", "/app/DockerNetExample.dll" ]
Build your image use docker build . -t dotnetexample
Run a container with previous image. docker run --name dotnetexample -p 8081:80 -d dotnetexample
Check your container. docker ps
. You would see like this.
Note: If you use Firefox, the return will be like this, the value maybe will be different, since it returns randomly.
Please check net6.0 branch.
Please check net7.0 branch.
MIT
Thank you for visiting this tutorial. If you have any questions or suggestions, please comment in here.