Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant access my Docker DotNet core website

I have run in to a dead end. I have a dotnet core 1.0.0 app I am trying to get up and running. It works great from linux and from windows. Now I am trying to get it into docker. I have made this docker file:

FROM microsoft/dotnet:1.0.0-preview2-sdk

COPY . /app
WORKDIR /app/app
RUN ["dotnet", "restore"]

ENTRYPOINT ["dotnet", "run"] 

It simply just copies code into app folder in docker image and restore dependencies and then runs it. When I try to run it, it starts up as everything is working and prints same as it was on windows or linux start up.

Docker Console

Command for running the project:

docker run --name dotNetWeb -p 8080:8080 kiksen1987/dotnetcore

Link to Code: https://github.com/kiksen1987/dotnetcore

Link to Docker image: https://hub.docker.com/r/kiksen1987/dotnetcore/

I really have no idea what is going wrong. I have more or less taking the same approach as 99% of my other projects.

Any feedback to improve this question would be nice aswell :)

like image 273
Kiksen Avatar asked Jul 02 '16 19:07

Kiksen


2 Answers

Finally.

I found this blog post: http://dotnetliberty.com/index.php/2015/11/26/asp-net-5-on-aws-ec2-container-service-in-10-steps/

Even though it used an old version of the dotnet core there was an important point I had overseen;

Notice that I’ve provided an extra parameter to the dnx web command to tell it to serve on 0.0.0.0 (rather than the default localhost). This will allow our web application to serve requests that come in from the port forwarding provided by Docker which defaults to 0.0.0.0.

Which is pretty damn important.

Solution:

var host = new WebHostBuilder()
            .UseKestrel()
            .UseStartup<Startup>()
            .UseUrls("http://0.0.0.0:5000")
            .Build();

Old code:

var host = new WebHostBuilder()
            .UseKestrel()
            .UseStartup<Startup>()
            .UseUrls("http://localhost:5000")
            .Build();

Which is wery frustrating since it seemed to work perfect in Linux and windows and app starting up in Docker, but never getting any requests. Hope this helps some other poor souls out there :)

like image 56
Kiksen Avatar answered Oct 25 '22 13:10

Kiksen


For newer .NET Core frameworks (such as 3.1 in this moment) this setting is on the launchSettings.json

"commandName": "Project",
  "launchBrowser": true,
  "applicationUrl": "https://localhost:5001;http://localhost:5000",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
like image 25
rmed1na Avatar answered Oct 25 '22 14:10

rmed1na