Jedi31 Jedi31 - 3 years ago 162
ASP.NET (C#) Question

Cannot acces Asp.Net Core on local Docker Container

I've created a app in core and create a dockerfile to generate a local image and run it.

FROM microsoft/dotnet:latest

COPY . /app


RUN ["dotnet", "restore"]

RUN ["dotnet", "build"]

EXPOSE 5000/tcp

ENTRYPOINT ["dotnet", "run", "--server.urls", ""]

Then, I've builded my image with the following command

docker build -t jedidocker/first .

Then, I've created a container with the following command

docker run -t -d -p 5000:5000 jedidocker/first

But when I run the following url into my host browser


I have an

is it a network problem? How can I solve it?

P.S: My windows version is 10.0.10586

Answer Source

I had the same issue and found the solution to this. You will need to change the default listening hostname. By default, the app will listen to the localhost, ignoring any incoming requests from outside the container. Change your code in program.cs to listen for all incoming calls:

public class Program
    public static void Main(string[] args)
        var host = new WebHostBuilder()


More info:

Make sure you are running the container with the -p flag with the port binding.

docker run -p 5000:5000 <containerid>

At the time of this writing, it seems that the

EXPOSE 5000:5000

command does not have the same effect as the -p command. I haven't had real success with -P (upper case) either.

Edit 8/28/2016:

One thing to note. If you are using docker compose with the -d (detached) mode, it may take a little while for the dotnet run command to launch the server. Until it's done executing the command (and any other before it), you will receive ERR_EMPTY_RESPONSE in Chrome.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download