create account

How to Dockerize Sample .NET Core API/Web Application by tomas-petrauskas

View this thread on: hive.blogpeakd.comecency.com
· @tomas-petrauskas · (edited)
$2.07
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](https://github.com/tomas-petrauskas/dockerize-netcore).

# Sample Application
Use sample code to create .NET Core Web Application
![nncggk.png](https://img.esteem.app/nncggk.png)
![24q684.png](https://img.esteem.app/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](https://hub.docker.com/_/microsoft-dotnet-core-sdk/) and [Runtime](https://hub.docker.com/_/microsoft-dotnet-core-aspnet/) 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](https://img.esteem.app/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](https://img.esteem.app/x7ltsw.png)

# Test

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

![5v73bk.png](https://img.esteem.app/5v73bk.png)

# Stop and Remove Container

`docker stop api && docker rm api`

![oduv34.png](https://img.esteem.app/oduv34.png)
👍  , , , , , , , , , , ,
properties (23)
authortomas-petrauskas
permlinkhow-to-dockerize-sample-net-core-api-web-application
categorydocker
json_metadata{"links":["https://github.com/tomas-petrauskas/dockerize-netcore","https://hub.docker.com/_/microsoft-dotnet-core-sdk/","https://hub.docker.com/_/microsoft-dotnet-core-aspnet/","http://localhost","http://localhost"],"image":["https://img.esteem.app/nncggk.png","https://img.esteem.app/24q684.png","https://img.esteem.app/6wx1dy.png","https://img.esteem.app/x7ltsw.png","https://img.esteem.app/5v73bk.png","https://img.esteem.app/oduv34.png"],"tags":["docker","c#",".net","api","web","dockerfile"],"app":"esteem/2.2.3-surfer","format":"markdown+html","community":"esteem.app"}
created2020-02-28 06:59:21
last_update2020-02-28 07:02:51
depth0
children1
last_payout2020-03-06 06:59:21
cashout_time1969-12-31 23:59:59
total_payout_value1.021 HBD
curator_payout_value1.051 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,605
author_reputation639,921,382,021
root_title"How to Dockerize Sample .NET Core API/Web Application"
beneficiaries
0.
accountesteemapp
weight300
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,900,831
net_rshares8,744,001,076,280
author_curate_reward""
vote details (12)
@steemitboard ·
Congratulations @tomas-petrauskas! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

<table><tr><td><img src="https://steemitimages.com/60x60/http://steemitboard.com/img/notifications/firstcommented.png"></td><td>You got a First Reply</td></tr>
</table>

<sub>_You can view [your badges on your Steem Board](https://steemitboard.com/@tomas-petrauskas) and compare to others on the [Steem Ranking](https://steemitboard.com/ranking/index.php?name=tomas-petrauskas)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



###### [Vote for @Steemitboard as a witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1) to get one more award and increased upvotes!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-tomas-petrauskas-20200228t070453000z
categorydocker
json_metadata{"image":["https://steemitboard.com/img/notify.png"]}
created2020-02-28 07:04:51
last_update2020-02-28 07:04:51
depth1
children0
last_payout2020-03-06 07:04:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length815
author_reputation38,975,615,169,260
root_title"How to Dockerize Sample .NET Core API/Web Application"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id95,900,928
net_rshares0