An Interest In:
Web News this Week
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
October 20, 2021 03:57 pm GMT
Original Link: https://dev.to/berviantoleo/web-api-in-net-6-docker-41d5
Web API in NET 6 Docker
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.
Project Preparation
- 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 DocketNetExample
- Your project is ready now. :)
Prepare for Dockerfile
- Create your
Dockerfile
at the root, similar place with the.sln
file.
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine as buildWORKDIR /appCOPY . .RUN dotnet restoreRUN dotnet publish -o /app/published-appFROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine as runtimeWORKDIR /appCOPY --from=build /app/published-app /appENTRYPOINT [ "dotnet", "/app/DockerNetExample.dll" ]
Build the Image and Run the Container
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.
Note: If you use Firefox, the return will be like this, the value maybe will be different, since it returns randomly.
- Congrats. You are done. :)
Repository
Thank you
Thank you for visiting this tutorial. If you have any questions or suggestions, please comment in here.
Original Link: https://dev.to/berviantoleo/web-api-in-net-6-docker-41d5
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To