Forem

Mohsen Kokabi
Mohsen Kokabi

Posted on

2

Simplest sample of DotNetCore in Docker

Step 1 - create a DotNetCore web app

dotnet new webapp -o TestDotNetCoreWebApp

Step 2 - build

The way Visual Studio does this is

  • creating a build image docker
  • copy the project files there
  • making the build
  • copying the files back to your final image

here the purpose is to make it in the simplest form, so I am building locally.

cd .\TestDotNetCoreWebApp\

dotnet publish -c Release -o out

Step 3 - Create the docker image

First we need a docker file. You can use an editor but I am just using powershell.

new-item -path "Dockerfile" -ItemType "file" `
-Value 'FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS runtime
WORKDIR /app 
COPY out ./ 
ENTRYPOINT ["dotnet", "TestDotNetCoreWebApp.dll"]' 

Build the image

docker build . -t test-dotnetcore-webapp-docker-image

Step 4

docker run -it --rm -p 8080:80 --name test-dotnetcore-webap-docker  test-dotnetcore-webapp-docker-image

the --rm option will tell docker engine to delete your docker as soon as it stopps.

Step 5

That's all. Your application is running on http://localhost:8080

if you run the docker ps in another terminal you would see your docker instance running but as soon as you stop it with Ctrl+C in the first terminal, the docker will be deleted.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay