How to Dockerize Sample .NET Core API/Web Application

in #docker5 years ago (edited)

I always use docker to run or publish my applications. It makes life so easy to build, publish and update applications on servers.

Example files

I uploaded all example files in to my GitHub Repository.

Sample Application

Use sample code to create .NET Core Web Application
nncggk.png
24q684.png

Docker Ignore

To build an application we only need Source Code, let's ignore unnecessary files like ./obj or ./bin.

Dockerfile

We will use Microsoft official SDK and Runtime Docker Containers to Build and Run .NET Core Application. This will make Application Container lighter since it will not include Source Code, only artifacts and libraries etc. Please replace Application name if needed.

Build

Build Docker Container from Dockerfile file in current directory:
docker build -t web-application .

6wx1dy.png

Execute

Run built web-application container in detached mode with api name and Port 80 accessible to localhost:
docker run -d -p 80:80 --name api web-application

x7ltsw.png

Test

To test if Application runs, open http://localhost URL in a Web Browser.

5v73bk.png

Stop and Remove Container

docker stop api && docker rm api

oduv34.png

Sort:  

Congratulations @tomas-petrauskas! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You got a First Reply

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Vote for @Steemitboard as a witness to get one more award and increased upvotes!