Skip to main content
Notice removed Canonical answer required by CommunityBot
Bounty Ended with no winning answer by CommunityBot
Notice added Canonical answer required by Gutemberg Ribeiro
Bounty Started worth 50 reputation by Gutemberg Ribeiro
Be more specific this question is regarding docker for windows
Link

Expose container port to Host using Docker for Windows in Windows 10

Source Link
Gutemberg Ribeiro
  • 1.5k
  • 2
  • 22
  • 45

Expose container port to Host

I've reading docker API and trying to create a simple container and expose 1 port.

In my example, I have an application that listen on TCP port 9595 inside the container and I want to access it from outside world (i.e. the host of the container) on port 9090.

When creating the container I have "ExposedPorts": { "9595/tcp: {}" } and the "PortBindings": { "9595/tcp": [{ "HostPort": "9090" }] }.

So, if I access from the Host machine http://container_internal_ip:9595 it works! However, when I access http://localhost:9090, which is what I expect using this port map feature, it doesn't work...

While running docker port containerID I have 9595/tcp -> 0.0.0.0:9090 and that should means, when connecting to any IP on the host, at port 9090, forward to the container in port 9595.

So, what is wrong here? Why can't I connect to 9090?

I appreciate any clarifications.