Repository navigation
Description
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
panmanphil commentedon Nov 5, 2016
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.
rn commentedon Nov 5, 2016
@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).
panmanphil commentedon Nov 6, 2016
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.
friism commentedon Nov 6, 2016
@panmanphil the containers are currently only available on the container IP:
Details here: https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/
Rusk85 commentedon Apr 30, 2017
Is this still an issue. Because I tried it with the lastest version of Docker on Win10Pro and
netstat -ap | grep PORTgave me nothing.jonstelly commentedon May 13, 2017
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.
szydan commentedon May 23, 2017
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
vguna commentedon Jul 16, 2017
@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:
Starting stopping docker image via
dockeron 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?vguna commentedon Jul 18, 2017
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.csthere something likevar nat = Container.NetworkSettings.Networks["nat"];. This silently fails, because in my json there's only a "bridge". After changing that, it starts to bind to172.17.0.2- which doesn't work because with the docker-machine, the IP of the VM has to be used -192.168.99.100in 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?TouDick commentedon Sep 19, 2017
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 ipis best suited to get an IP of machine created with default optionsvguna commentedon Sep 19, 2017
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!
58 remaining items
krispetkov commentedon Sep 25, 2019
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.
aslze commentedon Sep 28, 2019
Someone proposes as a workaround to access
<docker-machine ip>:<exposed port>instead oflocalhost:<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)
Abhijeetdutt commentedon Nov 10, 2019
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
Make the docker db fixture provide the host for the connection string
tobystic commentedon Jan 11, 2020
This worked for me. Routed all machine Port 80 host requests to Docker machine IP on Port 80:
obtained docker machine IP : docker-machine ip 'machine name'
machineIP:80 on browser
fazalWahid56 commentedon Jan 14, 2020
Issue still exist for me on windows 10 Pro, Build 18363.
tried everything mentioned above. In my case
docker-machine lsreturns empty sodocker-machine ipis not working for me.human2040 commentedon Jan 28, 2020
Got it to work using a combination of @szydan comment:
along with @joshijimit comment:
fenchu commentedon Feb 17, 2020
A simpler way is to just use docker inspect to get the ipadress
dhruvbitid commentedon Mar 3, 2020
thanks @joshijimit , its really helpful,
devilvole commentedon Mar 4, 2020
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.
Haley-Zhu commentedon Mar 17, 2020
<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.
jesselawson commentedon Mar 26, 2020
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!
docker-robott commentedon Jun 18, 2020
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