Rasa Govinda das avatar

How to Dockerize Sample .NET Core API/Web Application

tomas-petrauskas

Published: 28 Feb 2020 › Updated: 28 Feb 2020How to Dockerize Sample .NET Core API/Web Application

How to Dockerize Sample .NET Core API/Web Application

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

Leave How to Dockerize Sample .NET Core API/Web Application to:

Written by

(Tomas Petrauskas)

Read more #docker posts


Best Posts From Rasa Govinda das

We have not curated any of tomas-petrauskas's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Rasa Govinda das