3

I have two windows machines Machine A, Machine B running Windows 10 with Hyper-V. Both machine A & B are on the same network.

On Machine B I install docker using the Windows installer. I pull an image and then run it with:

docker run -p 1337:1337 --name my-image

On machine B I can then access the http end point that is exposed by opening a browser window to http://127.0.0.1:1337.

However I cannot seem to open that same http end point from machine A with:

http://machineA.ip.address:1337

There is no firewall between machine A and B.

Clearly I have a NAT problem between machine A and B when it comes to accessing the docker container on Machine B.

How do I access the HTTP end point exposed by the docker container running on Machine B from Machine A?

2
  • 1
    try with docker run -p 0.0.0.0:1337:1337 --name my-image
    – fly2matrix
    Oct 31, 2018 at 11:46
  • @fly2matrix Doh! Sp obvious. Happy to mark that as an answer if you like?
    – TheEdge
    Nov 5, 2018 at 11:30

1 Answer 1

4

You have to expose docker guest port of container to bind it with host port.

$ docker run -p 0.0.0.0:1337:1337 --name my-image

Above command will bind it with all the network-interfaces.
If you want you can restrict access to specific network-interface by specific it's IP address.

3
  • Isn't "bind to all interfaces" the default? Or is Docker for Windows special here?
    – David Maze
    Nov 5, 2018 at 11:40
  • when you specify 0.0.0.0 that means bind it with all the interfaces.
    – fly2matrix
    Nov 5, 2018 at 11:41
  • @DavidMaze I am guessing Windows is special here as it was only binding to localhost
    – TheEdge
    Nov 6, 2018 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.