user9124444
user9124444

Reputation:

Running a dotnet applicaiton in linux using docker

I've created a simple application, basically it is the default application that comes out of the box when you create an asp net project the only thing I've added is swagger. so in the Properties>launchsettings.json I've set the launch URL to point to swagger ui.

I just want to run it on a linux container and be able to access it on my windows host.

I'm running on a windows 10 using docker for windows with a linux containers setting.

So following are the steps

create a release version

   dotnet publish --configuration Release -o dist .\myApi.csproj (tried using the .sln file as well)

run the container

   docker run --rm -it -v pathTo_dis:/usr/app --name aspApp mcr.microsoft.com/dotnet/core/aspnet:latest

Inside the container I'm running the published app

 dotnet /usr/app/myApi.dll

I'm getting the

Now listening on : http://[::]:80

In another powershell I'm inspecting the container for the IPAddress this is it 172.17.0.3 and when I enter the Ip in the browser I get

The site can't be reached

If i try an access the site using localhost:5003

This localhost page can’t be found

So, how can you run a .net core app, in a linux container and have access to it ?

Upvotes: 0

Views: 700

Answers (1)

fliedonion
fliedonion

Reputation: 952

maybe you need use port option to allow access from outside container.

docker run --rm -it -p 8000:80 -v pathTo_dis:/usr/app --name aspApp mcr.microsoft.com/dotnet/core/aspnet:latest 

then you can access http://localhost:8000

note: 8000:80 first number(8000) is host port and second one(80) is container port.

Upvotes: 2

Related Questions