Skip to content

Docker for windows is not mapping ports to localhost #204

Closed

Description

@panmanphil

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

Activity

  1. panmanphil commented on Nov 5, 2016

    @panmanphil
    Author

    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.

  2. rn commented on Nov 5, 2016

    @rn
    Contributor

    @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).

  3. panmanphil commented on Nov 6, 2016

    @panmanphil
    Author

    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.

  4. friism commented on Nov 6, 2016

    @friism

    @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/

  5. Rusk85 commented on Apr 30, 2017

    @Rusk85

    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.

  6. jonstelly commented on May 13, 2017

    @jonstelly

    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.

  7. szydan commented on May 23, 2017

    @szydan

    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

  8. vguna commented on Jul 16, 2017

    @vguna

    @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?

  9. vguna commented on Jul 18, 2017

    @vguna

    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?

  10. TouDick commented on Sep 19, 2017

    @TouDick

    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

  11. vguna commented on Sep 19, 2017

    @vguna

    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!

  12. 58 remaining items

  13. krispetkov commented on Sep 25, 2019

    @krispetkov

    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.

  14. aslze commented on Sep 28, 2019

    @aslze

    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)

  15. Abhijeetdutt commented on Nov 10, 2019

    @Abhijeetdutt

    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

  16. tobystic commented on Jan 11, 2020

    @tobystic

    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

  17. fazalWahid56 commented on Jan 14, 2020

    @fazalWahid56

    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.

  18. human2040 commented on Jan 28, 2020

    @human2040

    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.

  19. fenchu commented on Feb 17, 2020

    @fenchu

    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",
    
  20. dhruvbitid commented on Mar 3, 2020

    @dhruvbitid

    thanks @joshijimit , its really helpful,

  21. devilvole commented on Mar 4, 2020

    @devilvole

    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.

  22. Haley-Zhu commented on Mar 17, 2020

    @Haley-Zhu

    <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.

  23. jesselawson commented on Mar 26, 2020

    @jesselawson

    @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!

  24. docker-robott commented on Jun 18, 2020

    @docker-robott
    Collaborator

    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

  25. locked and limited conversation to collaborators on Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions