I'm new to Docker. My Docker Desktop for Windows version is 19.03.5.
I want to expose port 2375 from Docker desktop for windows, but if I use the GUI setting,
that only can be accessed via tcp://127.0.0.1, My inner IP address 192.168.3.9 doesn't work.
https://learn.microsoft.com/en-us/virtualization/windowscontainers/manage-docker/configure-docker-daemon.
The document said to edit the C:\ProgramData\Docker\config\daemon.json and add "hosts": ["tcp://0.0.0.0:2375"], but it's doesn't work for any IP address, I'm very sure I did it as the document.
So what should I do can make access via tcp://192.168.3.9 from another computer which in the same subnet?
5 Answers
In some configuration (WSL2 backend / Linux container), you cannot force com.docker.proxy.exe to expose TCP port 2375 (it will bind 127.0.0.1:2375 for ever)
Use a simple NAT forwarding rules
netsh interface portproxy add v4tov4 listenport=2375 listenaddress=[public IP, NOT 0.0.0.0] connectaddress=127.0.0.1 connectport=2375
To achieve what you want
-
1
-
@ZachSmith Please edit your comment and add the exact failing command line, please– 131Aug 2, 2021 at 8:01
-
2Hi - I can't remember the exact cmd that ended up working. I think that
listenaddress=[public IP, NOT 0.0.0.0]was the problem (I think it's likely that this is a note and not a directive NOT to bind on the all address interface?). So probably my error Aug 2, 2021 at 8:42 -
Similar to the @131 answer. The issue is that Docker runs in 2375 but its bound just for localhost in some setups (WSL2 backend / Linux container)
This should work running as administrator:
netsh interface portproxy add v4tov4 listenport=3375 listenaddress=0.0.0.0 connectaddress=127.0.0.1 connectport=2375
Then you could execute in the client
DOCKER_HOST=192.168.1.1:3375 docker ps
or
docker -H tcp://192.168.1.10:3375 ps
where 192.168.1.1 is your the Docker host IP
-
I don't know if this changed recently but this only worked for me if I used IPv6 on the connect side
netsh interface portproxy add v4tov6 listenport=3375 listenaddress=0.0.0.0 connectaddress=[::1] connectport=2375Oct 25, 2022 at 15:49
Docker doesn't run native on Windows. It actually creates a Linux VM where it runs the docker daemon. You can see this VM with VirtualBox (assuming you like many others use VirtualBox for virtualization).
For this reason, in order to get your setup you need to modify this VM. You need to make sure its network interface is in NAT mode and then in the advance settings you can forward your port (2375) from host to guest. Restart Docker and it should work.
-
Emm...Docker desktop for windows use hyper-v, Do you mean to modify the Hyper-V network and forward requests from port 2375 ?– DengFeb 10, 2020 at 14:14
-
Yes, the logic is the same for Hyper-V. The main idea is that the docker daemon runs in a different machine. So when you tell docker to use localhost or any of its variants, it will use its own localhost which is not the one you mean.– MihaiFeb 10, 2020 at 14:23
-
3Is that
netsh interface portproxy add v4tov4 listenport=2375 listenaddress=192.168.3.9 connectaddress=172.17.32.1 connectport=2375right? the 172.17.32.1 is the hyper-v ip address, but it doesn't work. error msg: ``` Get 192.168.3.9:2375/v1.40/containers/json?all=1: read tcp 192.168.3.9:24150->192.168.3.9:2375: wsarecv: An existing connection was forcibly closed by the remote host```– DengFeb 10, 2020 at 14:42
The GUI setting is a linux container, that's the problem, switch to the windows container and edit the C:\ProgramData\Docker\config\daemon.json and add "hosts": ["tcp://0.0.0.0:2375"] gonna be work.
-
This didn’t work for me, and instead Docker wouldn’t start up. Docker Desktop has a UI to edit this config, but if you break it and docker won’t start up, you can’t reach the UI. The config file to edit turned out to actually be in
%HOMEPATH%\.docker\daemon.jsonOct 3, 2022 at 15:31 -
Where should I expect to find this file? C:\ProgramData\Docker doesn't exist.– MikeBMay 9 at 17:46
If you are running docker daemon on Windows
Other than:
netsh interface portproxy add v4tov4 listenport=3375 listenaddress=0.0.0.0 connectaddress=127.0.0.1 connectport=2375
it was required for me to add a rule in the windows firewall for inbound traffic + enable Edge traversal. In another way all my traffic was blocked by the default Query User block rule:
This filter blocks any inbound packets for which there is no explicit rule to allow the packet, unless the user has allowed through the Query User pop up.
To add a rule to firewall:
- Go to
Windows Security->Advanced Settings->Inbound Rules->New Rule - Chose
Port-> Next ->TCP,Specific local ports: 2375 or 3375, depending on which port you forwarded; add a list of other ports that you would like to request remotely. - After finishing creating rule, select it from the list and open properties. Go to
Advanced->Edge Traversaland selectAllow edge traversal.