Docker – localhost not working on Windows


I recently publish a post about “How to configure docker on Windows”. But after some windows update, localhost processing stopped working.

Example

Let us look at the example with the same dockerfile.

FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app
RUN ["dotnet", "build"] 
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000
ENV ASPNETCORE_ENVIRONMENT development
 
ENTRYPOINT ["dotnet", "run"]

After building the image and turning it on. We are getting information that our application is working on port :5000

docker stop working

But if we try to run it on http://localhost:5000/ , our website is not responding.

Not responding

Let’s look at what docker ip works on. To do this we need to enter the docker inspect command plus name of our image. In our case:

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" 24271

docker inspect

On this ip our application works!

docker windows

So what happend?

This is described in detail HERE.

But in brief:

Container endpoints are only reachable from the Windows host using the container’s IP and port.

We must admit that the natural environment for a docker is linux. That’s why many windows updates can make us bloody in future, so in my opinion the best environment for hosting applications is linux (especially the core version allows us to do so).

Leave a Reply

Your email address will not be published. Required fields are marked *