docker / for-win

Bug reports for Docker Desktop for Windows

Home Page:https://www.docker.com/products/docker#/windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Docker for windows is not mapping ports to localhost

panmanphil opened this issue · comments

Expected behavior

Using a simple example of the FROM microsoft/iis and EXPOSE 8000 as shown in the samples, this type of command runs, and I can access the port on the ip address shown from docker inspect. However when I use port mapping like so:

docker run -d -p 8080:8000 --rm iissite

I expect to be able to access the site from http:/localhost:8080, instead only the nat ip and EXPOSE port are reachable.

Actual behavior

unable to connect

Information

  • Diagnostic ID from "Diagnose & Feedback" in the menu.
  • a reproducible case if this is a bug, Dockerfiles FTW
  • page URL if this is a docs issue or the name of a man page
  • host distribution and version (Windows version, build number, etc)
    Client:
    Version: 1.12.0
    API version: 1.24
    Go version: go1.6.3
    Git commit: 8eab29e
    Built: Thu Jul 28 23:54:00 2016
    OS/Arch: linux/amd64

Server:
Version: 1.12.2-cs2-ws-beta
API version: 1.25
Go version: go1.7.1
Git commit: 050b611
Built: Tue Oct 11 02:35:40 2016
OS/Arch: windows/amd64

windows version 1607 build 14393.351

Dockerfile
FROM microsoft/iis
RUN mkdir C:\site
RUN powershell -NoProfile -Command
Import-module IISAdministration;
New-IISSite -Name "Site" -PhysicalPath C:\site -BindingInformation "*:8001:"
EXPOSE 8001
ADD . /site

Steps to reproduce the behavior

docker run -d --name site iissite
(from powershell)
docker inspect --format='{{.NetworkSettings.Networks.nat.IPAddress}}' site
wget "http://:8001" -UseBasicParsing
You see StatusCode 200

docker stop site
docker rm site
docker run -d -p 8080:8001 --name site iissite
wget "http://localhost:8080" -UseBasicParsing

get "unable to connect to the remote server"
also try trying the ip of ethernet0 from ip config

with linux containers and previous version of docker for windows, this works and works well

Running the same type of -p option on Windows 2016 also does not work. On the Windows 2016 I tried all of the available ip addresses but only the address shown from docker inspect and the original port from the EXPOSE statement worked. I could swear this worked before, and have been doing this for all of this year with the linux/mac versions of docker.

@panmanphil thanks for the report. Probably confusing, but networking for Windows containers is done differently to the way we run Linux containers on Windows (and the Mac). For Linux containers we use a component, called VPNKit, which watches containers with exposed ports being created and exposes them on the localhost. For Windows containers this component is not used and containers and their ports are only accessible via the NATed IP address.

This is expected behaviour and I'm closing this issue. We should probably add this to our documentation (/cc @londoncalling).

This isn't just the loopback connector that isn't working. I tried all the ip addresses on the box listed from ipconfig, and none of them could be used to connect. Only the nated container ip address and port worked. What is the purpose of having -p then if not to put the port on one of the host's ip addresses?

Yes please do update the documentation, I can't be the first to spend a bunch of time on this.

@panmanphil the containers are currently only available on the container IP:

 docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' <container>  

Details here: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/

Is this still an issue. Because I tried it with the lastest version of Docker on Win10Pro and netstat -ap | grep PORT gave me nothing.

This is still an issue but if/when it will be resolved seems murky. For anyone else that might be frustrated, I've put together an admittedly sub-optimal work-around for this limitation, DockerProxy. It's a dotnet core console app that proxies from localhost:{port} -> docker-container:{port}. It monitors docker and will start/stop listening on ports as containers come up or down.

For me NATing the port in VirtualBox worked
Go to VirtualBox -> Your BOX -> Settings -> Network ->
Choose NAT
Open Advanced
Click Port Forwarding
Add new rule to map whatever port you need from host to guest
Click OK, OK
Then stop, start the BOX

@jonstelly : thanks for the docker proxy. But it doesn't seem to work for me. I just start it on my Windows 7 Home like this:

D:\Coding\DockerProxy>dockerproxy
Hosting environment: Production
Content root path: D:\Coding\DockerProxy
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

Starting stopping docker image via docker on cmd line doesn't have any effect. I'm missing something here? I also don't understand why it is listening on 5000. Can it be remote controlled or something?

Ok, I digged deeper into the rabbit hole and debugged/compiled my own version to see what's the problem here. Forget about the listening stuff I wrote :).

First of all, I have to run the docker tools (docker-machine) on my Windows 7. I think this is the main reason, that DockerProxy is not working out of the box. I did two things to make it work:

In Proxy.cs there something like var nat = Container.NetworkSettings.Networks["nat"];. This silently fails, because in my json there's only a "bridge". After changing that, it starts to bind to 172.17.0.2 - which doesn't work because with the docker-machine, the IP of the VM has to be used - 192.168.99.100 in my case. So for testing I just hardcoded the ip to it, and now it seems to work.

I think it should be possible to get that IP via docker-machine ip. Are there any plans to add docker-tools support to docker proxy?

This is ridiculous...
I spent hours looking why my ports are not forwarded as in getting started guide and then I find this....

This should work out of the box! And this is still not mentioned in documentation or am I missing something?!

Moreover default machine created like in getting started guide is not NAT-ted so doing anything like docker inspect --format '{{ .NetworkSettings.Networks.nat.IPAddress }}' returns only

This issue should be reopened and fixed properly. Instead of avoiding the proper solution. This is at end what docker should just do without excuses. Why do anyone need docker container with no possibility to connect to it anyway?

Edit:
PS. docker-machine ip is best suited to get an IP of machine created with default options

In the end I switched to Windows 10 Professional since this solution wasn't reliable :(. I wanted to avoid that at all costs. But docker and Win7 is a pain. With the native docker it works quite well now!

commented

The only way we can access exposed port in windows is through

> http://<docker-machine ip>:<exposed port>

. I have tried every ip address listed in my ipconfig -all list. At last I found the correct ip from command docker-machine ip. Worked for me in windows 10 pro.

So, I have installed the http docker image

$docker run -d --name MyWebServer httpd
7d4f8eb312d1463fd67c7d9169c5bad17581c0d1f5b0319de8c9bfa32df06150

It's running

$docker ps -all
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS               NAMES
df3a451e696f        httpd               "httpd-foreground"   20 minutes ago      Up 20 minutes       80/tcp              MyWebServer

The dockerfile for this image exposes port 80:

EXPOSE 80
CMD ["httpd-foreground"]

When I look at the settings in my Window Docker I see:
image
But when I browse to 10.0.75.0
image

I found this very good blog article where it explains how to get around this.

$docker run -d --name MyWebServer -P httpd
f552aa1667f351d63f1cf7e3dae7ab336837ca49c38838dc53c7f3c038dc5c88

Using the -P flag apparently assigns a randomised port number to expose. Reassuringly I saw a Windows Security Alert:
image

$docker port MyWebServer
80/tcp -> 0.0.0.0:32768

but, dissapointingly... http://10.0.75.0:32769 still gives me
image

Thanks @joshijimit, I eventually tried your tip of trying all of the addresses given by ifconfig -a and one of them worked

wifi0     Link encap:UNSPEC  HWaddr 74-E5-43-A7-A0-A1-00-00-00-00-00-00-00-00-00-00
          inet addr:10.0.0.13  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::d96a:8316:a0d:20b3/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

image
I don't understand why the Docker settings panel tells my it's using 10.0.75.0 but the web server can only be reached on http://10.0.0.13:32769/

commented

Glad to hear it helps you @nickweavers. And yes I am also not sure why there is a conflict in IP address in Windows with docker.

Hi all,

We now have support for using localhost/loopback to access your container's published ports on Windows 10! Here's the announcement for this support, which is available starting with Windows 10 Insider build 17025.

Have any of you been able to try this already? If so, we'd love to hear your feedback. Let us know whether or not this support is meeting your needs. Feel free to reply here with comments or email our team at sdn_feedback@microsoft.com.

--Kallie Bracken
PM, Windows Core/Container Networking at Microsoft

commented

Cool I will give it a try.. Thanks for update.

nickw@DESKTOP-OREBB4V:~
$docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
f49cf87b52c1: Pull complete
02ca099fb6cd: Pull complete
de7acb18da57: Pull complete
770c8edb393d: Pull complete
0e252730aeae: Pull complete
6e6ca341873f: Pull complete
2daffd0a6144: Pull complete
Digest: sha256:b5f21641a9d7bbb59dc94fb6a663c43fbf3f56270ce7c7d51801ac74d2e70046
Status: Downloaded newer image for httpd:latest
nickw@DESKTOP-OREBB4V:~
$docker run -d --name MyWebServer httpd
9b100d3a54980d91745697e99f5771eb035d5b7d52d268a8dd044a00d77fbbdf
nickw@DESKTOP-OREBB4V:~
$curl localhost
curl: (7) Failed to connect to localhost port 80: Connection refused

Sadly not working
Lets try mapping dockerfile exposed port on the docker run command
First we need to cleanup

nickw@DESKTOP-OREBB4V:~
$docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED              STATUS              PORTS               NAMES
9b100d3a5498        httpd               "httpd-foreground"   About a minute ago   Up About a minute   80/tcp              MyWebServer
nickw@DESKTOP-OREBB4V:~
$docker stop 9b100d3a5498
9b100d3a5498
nickw@DESKTOP-OREBB4V:~
$docker rm 9b100d3a5498
9b100d3a5498

Now we can try again

nickw@DESKTOP-OREBB4V:~
$docker run -d --name MyWebServer -p 80:80 httpd
5162d436d3deea1ff5638ec3065787e479df668425c038c6262e246447cf7af1
nickw@DESKTOP-OREBB4V:~
$docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                NAMES
5162d436d3de        httpd               "httpd-foreground"   7 seconds ago       Up 5 seconds        0.0.0.0:80->80/tcp   MyWebServer
nickw@DESKTOP-OREBB4V:~
$curl localhost
<html><body><h1>It works!</h1></body></html>

This time we're good, but is this what you meant by

We now have support for using localhost/loopback to access your container's published ports on Windows 10!

since there was no mention of having to use the -p flag?

Hi, I am new on this stuff, could I know is the "exposed" work properly in microsof/iis?
Even I used ip of below, still cannot use the exposed port function.

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

ed2248e00f74 microsoft/iis "C:\ServiceMonitor..." 12 minutes ago Up 12 minutes 0.0.0.0:12345->80/tcp amazing_wiles

commented

@kimtso , As per the comment from @kallie-b and @nickweavers it seems you should be able to access iis through localhost:80 (i.e just localhost) if you are using the latest build. If you can't, try to run "docker-machine ip" command in your docker terminal and use that ip to access your IIS.

image

@joshijimit, where does the docker-machine command come from? It doesn't appear to be part of the docker client. My docker clients is

17.09.1-ce, build 19e2cf6

Am I missing something?

nickw@DESKTOP-OREBB4V:~
$docker --version
Docker version 17.09.1-ce, build 19e2cf6
nickw@DESKTOP-OREBB4V:~
$docker-machine ip
docker-machine: command not found
nickw@DESKTOP-OREBB4V:~
$
commented

@nickweavers
Not sure if it gets introduced in Docker version 17.10.0-ce. I have 17.10 version installed and docker-machine is showing the IP through it.

$ docker --version
Docker version 17.10.0-ce, build f4ffd25

@nickweavers if you are using Docker for Mac or Docker for Windows, then docker-machine is installed as a component. Go here for Windows or here for Mac, and scroll down to see "What the install includes" (last bullet in bold called What to know before you install).

If you don't have docker-machine installed for some reason, then I would run through the install process again, per those pages. You can download stable or edge versions of the installers from the linked pages:

Download Docker for Windows

Download Docker for Mac

You can get older versions of all installers from the release notes:

Docker for Mac release notes

Docker for Windows release notes

Docker Machine has been part of Docker CE from the start. Here is output for my system:

me:~ vicky$ docker --version
Docker version 17.09.1-ce, build 19e2cf6
me:~ vicky$ docker-machine --version
docker-machine version 0.13.0, build 9ba6da9

@nickweavers -- Yes, it looks like the behavior you've laid out is expected. However, you raise a good point--I did not include a set of example steps/commands in the blogpost to make it clear that -p/ --publish should be used to publish the ports in the first place. I'll add that!

commented

This still does not work in Version 17.12.0-ce-win47 (15139).

The only way to access services inside the docker container in docker for windows still appears to be to bind the service in the container to the public ip of the container (eg. 0.0.0.0:8080).

So here's a specific example:

By default redis-server binds to localhost, not to 0.0.0.0 in /etc/redis/redis.conf
That doesn't work.

Repro:

Setup, grab library/ubuntu and:

docker run -it -p 6379:6379 myredis
apt-get install redis-server redis-tools

You can login to a container, and run redis-cli no problem:

root@91270bd69bd9:/data# redis-cli
127.0.0.1:6379>

...but you cannot login via the public ip:

$ docker inspect 91270bd69bd9 | grep IPAddress
"IPAddress": "172.17.0.3",

root@91270bd69bd9:/data# redis-cli -h 172.17.0.3
Could not connect to Redis at 172.17.0.3:6379: No route to host
not connected>

Result: you can't login to redis on localhost:6379 from the host.

Now change the config in /etc/redis/redis.conf to:

bind 0.0.0.0

(and obviously, service redis-server restart)

Access via public ip?

root@91270bd69bd9:/data# redis-cli -h 172.17.0.3
172.17.0.3:6379>

Yes? From the host you can connect no problem.

ie. tldr; this is trivial to repro, and ports bound to localhost still don't work with port forwarding.

commented

I met with the same problem when trying "Tutorial for Debezium 0.7" (http://debezium.io/docs/tutorial/) with Docker Toolbox on Windows 8.1 (https://docs.docker.com/toolbox/toolbox_install_windows/).

Thanks @szydan for the port forwarding method. I added 6 rules manually and didn't restart VirtualBox or Docker and it worked!

Very confused about this whole topic as until very recently I was able to access my containers exposed ports from my Windows 10 Pro machine using localhost:<port>. There are still web ui URLs appearing in my browser cache (e.g. http://localhost:15672/#/ for Rabbit) that I know were working a couple of weeks ago.

I found this topic because it no longer works, wasn't expecting it to be the case that it should never have worked! I'm using Docker version 17.12.0-ce-win46 with Hyper-V rather than Virtualbox if that makes any difference. Been using Docker since October 2017 and was always able to access container exposed using localhost.

EDIT: Found I cannot access the containers from outside by any means so there must be something more fundamental wrong with the MobyLinux VM or vpnkit. The ports are showing as listening on 0:0:0:0 but nothing can connect on any IP address I try.

EDIT2: Working again after upgrading to 17.12.0-ce-win47

@comdw I am in the same bucket. I know this was working back in December. I used it to run a NodeJS image with an Express server and was able to access it through https://localhost:3000 (yes, with SSL too!). And now I have a Wildfly server in a container and I can't reach it no matter what I try. IP/loopback..nothing works. I am using the Edge version of Docker For Win though. I have a corporate proxy running on my machine and only the Edge version of Docker has the fixes in VPNKit for that to work. I am going to try and revert to the Stable channel version and see what I get.


EDIT: I got it working. I am on the latest stable version again. This was actually my own fault. What led me to the issue was when I read in some github issue where someone had bound their "redis" server inside a container to "localhost" instead of "0.0.0.0", which would ultimately bind the service to all network interfaces. This was the mistake I made as well. I fixed the configuration of my service to bind on all interfaces, after which I was able to reach it from my machine simply using http://localhost:8080. This wasn't a problem for me with the Express server container before, and I guess it's because Express perhaps, by default, binds to all interfaces and not just localhost.

tl;dr; With the latest version of Docker for Windows, loopback addressing for docker (linux) containers does work. Here are a few things to check if it doesn't work for you:

  • Check that your service binds on all interfaces.
  • Check if you have the latest Docker for Windows installed
  • Check if you have all of the Windows 10 Pro updates installed

I am still getting this issue on Windows 10 Pro (all updates installed) and running docker version 17.12.0-ce-win47 (15139)

I have verified that my image is using 0.0.0.0 as the serving address and tried several different ports (8181, 8080, 9315, etc.); the port does not respond on any IP (docker system IP, localhost, 0.0.0.0, etc.), but when I attach a shell to the container, I get a valid response from the port.

I have tried manually exposing the post (--expose 8181), but that has no effect.
Given that this same exact configuration runs perfectly on my linux machine, I think the issue still persists in windows...

Also having an absolute disaster trying to run docker toolbox that includes a Linux VM running with virtualbox. Tried everything multiple google searches provide, and nothing has worked.
What is especially frustrating is I managed to get access a week or so ago, but coming back to it with the exact same method something has broken..

I asked on Stack Overflow but not getting much response any more.

@cryocaustik what is your image based on? When your container is running, type docker ps in PowerShell, and verify that the ports are listening on 0.0.0.0. Something like this 8080 -> tcp:0.0.0.0. If you don't see that and just the port number listed, that means your service is not bound to listen on all interfaces.

@praneetloke I am following the instructions here from a tutorial that works perfectly on Linux

I am not near my computer at the moment so I cannot screenshot the exact state of docker ps, but I had it showing that before and still none of the IPs/ports we're responding

@praneetloke @joshwapiano after digging around some more, I found that using --expose $PORT was not sufficient on windows; instead, as wsargent suggested in his cheat sheet, I used -p 127.0.0.1:$HOSTPORT:$CONTAINERPORT when running the image, which resolved the issue and made the app available on 127.0.0.1:$HOSTPORT 💚

@cryocaustik the difference is because --expose only exposes the port. It might be equivalent to the EXPOSE instruction in your Dockerfile. The difference being you are exposing from your container a port at runtime. -p actually publishes your port to the host. You can read about them here.

Using the docker-machine ip:port was the solution for me.

@szydan
problem solved by following your step.
but except that we don't need to restart virtualbox finally.

If I'm understanding the OP right, this problem is fixed (for Windows 10, at least) with the April 2018 Windows update. More at this MS Technet post (where you should look for "Localhost/loopback support for accessing containers". Sorry no anchor to offer.) Or for a more substantive discussion, from when it was first offered as an Insider's build, see this Nov 2017 technet post

Is this the same as #458? I experience this issue even after the April 2018 update.

Hi @cmeeren @carehart , speaking here on behalf of the Windows Core networking team.

You are correct that this feature was released in Windows Server, version 1803. Unfortunately, it turned out that a bug was introduced which broke functionality for a subset of users. To be more specific: if you had a network adapter which is connected (and has a 169.254.x.y IP address) localhost stopped working.

The workaround was to disable any remaining adapters which have a 169.254.x.y IP address assigned.

Meanwhile, we fixed this issue with Windows Insider build 17692 and above. We are still working on all the checkmarks that are needed to be able to propagate this fix to Windows April 2018 Update and Windows Server, version 1803. I will post back here if a KB is released.

I can confirm it works for me now, and that I have no network adapters with IP 169.254.x.y. I might have had such an adapter when I reported the problem.

@daschott FYI: I did not have this problem and localhost was working fine, but I was trying to resolve another issue and then I did:

  1. Uninstalled Docker for Windows, Hyper-V and Containers feature
  2. Rebooted.
  3. Removed all network adapters so I only had one for my wired connection
  4. Rebooted.
  5. Installed Docker for Windows, Hyper-V and Containers feature once again.

And now localhost/127.0.0.1 is not working at all for Windows containers, containers works fine using their assigned IP's . I don't have any adapters with the 169.254.x.y range....

So something else is also messing with this.

17704 insider build here, container with just plain ubuntu and python running a flask application on port 5000, docker ps shows 0.0.0.0:8080->5000, pointing to localhost:8080 yields nothing

Thx for following up, we will continue to try and reproduce this issue. To expedite the process,
@hosaka which docker version are you using? Is it only Linux containers or also Windows containers that do not work?
@pbering Which Windows Insider build/docker version are you using?

Also, I can confirm that we will release an update with the fix in Windows 10 April 2018 and Windows Server, version 1803. ETA is in July 2018.

@daschott, Windows 10 Enterprise 1803 build 17134.137 (not insider) and Docker is 18.03.1-ce-win65 (17513) (stable)

@daschott I haven't tried with Windows containers, only Linux so far. Windows Insider Preview Build 17704.rs_prerelease.180623-1611:

PS C:\wa\ix\ix-api-service> docker --version
Docker version 18.03.1-ce, build 9ee9f40
PS C:\wa\ix\ix-api-service> docker build -t "ix-api-service" .
...
PS C:\wa\ix\ix-api-service> docker run -p 5000:5000 ix-api-service
 * Serving Flask app "app" (lazy loading)
...
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

From another PS:

PS C:\> docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
11c81bdf5a93        ix-api-service      "/bin/sh -c 'python3…"   5 minutes ago       Up 5 minutes        0.0.0.0:5000->5000/tcp   confident_shtern
PS C:\> Invoke-RestMethod -Uri http://127.0.0.1:5000
Invoke-RestMethod : The underlying connection was closed: The connection was closed unexpectedly.

Running the Flask app without the container obv works:

PS C:\> Invoke-RestMethod -Uri http://127.0.0.1:5000

html
----
html

I'm not gonna dump the ipconfig /all here, but there are no ip addresses with the 169.254.x.y range.

@pbering
Thanks for patiently waiting. We backported the container localhost/loopback access fix for Windows April 2018 Update (Windows 10 version 1803) through KB4340917, available now.

To validate this fix, you can use docker run -p 8080:80 microsoft/iis command. Once the container is running, you should be able to use loopback and access the container using http://localhost:8080 or http://127.0.0.1:8080.

@hosaka Apologies for the delay here -- can you try the above steps and see if they work for you? Otherwise, does your flask app expect any specific ports? Can you access it by http://:5000?

I can confirm it works on the localhost address/port. Also that it is no longer accessible on the ip address shown by docker inspect. Not sure if that is by design or not, but I found it surprising at least.

@panmanphil Are you using http://:?
In my example linked above, I used container port 80. I think in your initial example you used port 8000.
Can you confirm what command you used to launch container and test the connectivity?

Yeah, false alarm! When accessing the container via it's network address, I needed to use the container port 80 not the host port 5000:

 tasty-app           "dotnet app/tasty-si…"   31 seconds ago      Up 6 seconds        0.0.0.0:5000->80/tcp   tasty

docker  inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' tasty
192.168.228.207

invoke-webrequest http://192.168.228.207:80/api/chow -usebasicparsing


StatusCode        : 200
StatusDescription : OK
Content           : ["sammy","yogurt","burger","burger","burger","not-bacon"]
RawContent        : HTTP/1.1 200 OK

invoke-webrequest http://127.0.0.1:5000/api/chow -usebasicparsing

StatusCode        : 200
StatusDescription : OK

I found a solution to the problem I was having Accessing a jenkins container via http://hostname:8080 from another network computer. My host is a windows 10 box running docker for windows (linux containers).

I had to manually open the port in the firewall settings. Worked immediately after I added the rule.
See:
https://www.tomshardware.com/news/how-to-open-firewall-ports-in-windows-10,36451.html

I found this solution and worked great:

route add 172.17.0.0 mask 255.255.0.0 10.0.75.2 -p

Just need to open powershell or CMD with Administration Permission and execute.

After trying a ton of these ideas, I just used this address to connect to the docker container!

http://host.docker.internal:8080

Note: This worked for me on Windows 10 Pro, running linux containers through WSL.

@SamuelBradley Can you confirm that this workaround is no longer needed in Windows Server 2019? There is a fix there for this known port-mapping issue.

@daschott sorry can't confirm for windows server as im using windows 10 though adding firewall rules isnt really a workaround its just a manuel step. In my experience Windows server would be more pedantic about firewall rules than a consumer edition like Windows 10.

I'm not sure if this is entirely true but this seems to have worked for me:

  1. I'm using Docker for Windows 10 Pro, but running a linux node container
    2, When I do a hostname -i from inside the container it gives me 172.17.0.2, so when I try http://172.17.0.2:3010, IT DIDNT WORK!
  2. After some hours, I found this thread, and it said something along "do ipconfig and try all the IPs". So I did and it worked. When I entered http://10.0.75.1:3010 it works!.
  3. I'm not sure if it is related but it is likely. Docker subnet is 10.0.75.0. Which tells me that each container will have its IP address based on that subnet (+1).

Hope this helps

The workaround using the ip given by the 'docker-machine ip' command worked for me
http://docker-machine-ip:8080 worked where
http://localhost:8080 did not

Same here, on Windows 10 HOME edition. Find your docker machine ip with docker-machine ip, then you can use that ip address if you are already mapped to port 80.

I'm still hitting issues with this with Windows 10 version 1809 (10.0.17763.379): openfaas/faas#1139. Are there still known problems here?

Edit: Never mind, it worked fine after restarting Docker.

So is the issue where docker doesn't map the ports to localhost a regression we're all going to ignore?

I've been using docker-for-win and it has been happily mapping the ports up until a couple months ago and again recently.

It maps the local ports for mac and linux, why would it not for windows?

No amount of restart/reinstall of docker has fixed this issue. It just loses all port mapping while the containers are running.

commented

Why this issue closed?

And how to solve it?
My server is 8765 and http://10.0.75.1:8765/ doesn't help to me.

@hadaev8 Apparently we just have to deal with the issue as it's not going to be fixed. Just restart your computer and reinstall docker everytime or buy a mac/install linux if you want a better experience.

My guess is that Docker on WSL2 will improve this experience... Hopefully.

Still getting the same issue, tried all options discussed above. I am not understanding why this issue marked as closed.

I am still having this problem. What is the recommended work around?

I just stopped using it for a month and it started working.

I had the same issue. To get the actual ip, use "docker-machine config". Use this ip instead of localhost.

That's a non-solution for any development that deals with OAuth integration and is unique to windows only. Works perfectly fine on Mac and Linux on localhost and Windows should be the same.

Hello guys, I think I found a solution for .net core applications. It seems that this is a configuration problem but not a Docker problem (at least at the present, maybe it was a Docker problem in the past). So the solution that worked for me:

In your Program.cs add .UseUrls("http://+:<your_port>") and try. This is in case that you are hosting your web application in the default .net core's web server Kestrel. By using the UseUrls method you are telling where the Kestrel web server should listen. Anything from the launchSettings.json file does not matter.

commented

Someone proposes as a workaround to access <docker-machine ip>:<exposed port> instead of localhost:<exposed port>. Yes, that works but is not a solution.

If I have a server in a Docker container, the docs say it can be accessed like localhost:80, but I have to first find the machine IP and go like `192.168.99.100:80'. That means it is in the (virtual) network interface between the host and the container. So it cannot be accessed by other physical machines.

How useful is a server that can only be accessed from the host machine? Or is there a way to expose it "publicly"?

(BTW, this is Docker Toolbox on Windows 10 Home)

For Windows, try this -

Go to cmd, run ipconfig

Wireless LAN adapter Wi-Fi:

Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : xvxvxvxvxvxvxvxvxvx
IPv4 Address. . . . . . . . . . . : 000000000 ------------> Use this as IP
Subnet Mask . . . . . . . . . . . : vxvxvxvxvxvx
Default Gateway . . . . . . . . . : vxvxvxvxvxvxv

docker run -d --name webs -P httpd
df18b38c638819e348ab90d219482f910ba

docker ps
df18b38c6388 httpd "httpd-foreground" 5 seconds ago Up 4 seconds 0.0.0.0:32768->80/tcp webs

then, use ${000000000}:32768

This worked for me. Routed all machine Port 80 host requests to Docker machine IP on Port 80:

docker run -d -p 80:80 'containerImagename'

obtained docker machine IP : docker-machine ip 'machine name'

machineIP:80 on browser

Issue still exist for me on windows 10 Pro, Build 18363.
tried everything mentioned above. In my case docker-machine ls returns empty so docker-machine ip is not working for me.

Got it to work using a combination of @szydan comment:

For me NATing the port in VirtualBox worked
Go to VirtualBox -> Your BOX -> Settings -> Network ->
Choose NAT
Open Advanced
Click Port Forwarding
Add new rule to map whatever port you need from host to guest
Click OK, OK
Then stop, start the BOX

along with @joshijimit comment:

The only way we can access exposed port in windows is through

> http://<docker-machine ip>:<exposed port>

. I have tried every ip address listed in my ipconfig -all list. At last I found the correct ip from command docker-machine ip. Worked for me in windows 10 pro.

A simpler way is to just use docker inspect to get the ipadress

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                                              NAMES
26203073615b        fido1:0001          "powershell.exe"    13 minutes ago      Up 13 minutes       0.0.0.0:8315->8315/tcp, 0.0.0.0:61904->61904/tcp   xenodochial_heyrovsky

docker inspect 26203073615b | findstr.exe IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "",
                    "IPAddress": "172.29.97.214",

thanks @joshijimit , its really helpful,

So disappointing to see this issue is still around after more than three years. And yes - I've wasted hours too trying to fix it before I stumbled on this thread.
I'm trying to automate (well duh!) as much of this as possible so rather than extracting the container IP I've been specifying it. Simple enough but you need to create a network with subnet and use that to run the image.

docker network create --subnet 172.18.01.0/24 --driver nat sql_net

docker run -itd --network sql_net --ip 172.18.01.12 -v e::e: humphriesj/windowssql:2019

In this case the SQL server image is then available at 172.18.01.12:1433 always.

<http://docker-machine ip:exposed port> works for me, I can see the view in the browser.
BUT, I have another problem.
When I change the code and save it, the view in the browser CANNOT refresh. The view of <http://docker-machine ip:exposed port> still remain showing the view before code change.
Does anyone knows how to refresh the performance in the browser <http://docker-machine ip:exposed port>?
I tried docker-compose down then docker-compose up again, but it doesn't work.

@kimtso , As per the comment from @kallie-b and @nickweavers it seems you should be able to access iis through localhost:80 (i.e just localhost) if you are using the latest build. If you can't, try to run "docker-machine ip" command in your docker terminal and use that ip to access your IIS.

image

For folks not able to use Docker on Windows because we don't have Pro, Enterprise, or Education edition, this was the correct way to get this all working. Thank you!

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked