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.
- .NET 6: https://dotnet.microsoft.com/download/dotnet/6.0
- Docker: https://docs.docker.com/get-docker/
- Create the Web API from template.
dotnet new webapi -o DockerNetExample
- Create the solution to link the project and link the project.
dotnet new sln
dotnet sln add DockerNetExample
- Your project is ready now. :)
- Create your
Dockerfileat the root, similar place with the
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.
- Check your API use browser or another things.
- Congrats. You are done. :)
Thank you for visiting this tutorial. If you have any questions or suggestions, please comment in here.