15

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.

3
  • The question doesn't have enough information. We need at least the docker command, what image is using or the Dockerfile. Windows containers or Linux containers? Commented Nov 1, 2016 at 18:34
  • Docker Remote API against what docker engine? Windows containers? Linux container? You cannot run a container without a base image. What image? You called the Docker Remote API how you called it? It is a resfful right? What command did you use? I cannot KNOW about what you are asking if you don't give ENOUGH information. Commented Nov 1, 2016 at 19:38
  • Sorry,I don't meant to be rude Carlos, but none of your comments were relevant to question. It doesn't matter to the question what is the image. What matters is that according to the API documentation, I have port 9090 exposed to outside the container and mapped to port 9595 inside the container and that isn't working. Netsh will not affect anything on the container behavior or configuration. Commented Nov 1, 2016 at 19:52

2 Answers 2

5

The port really is being exposed to the 'outside world' as expected, it just happens to be inaccessible from the container host machine itself on the loopback interface (localhost or 127.0.0.1) due to a current windows networking limitation. Rather than trying to access it via the loopback interface on the container host, try to access it from another machine on the network, using the container host ip and the containers exposed port number.

There is a good writeup for this at https://blog.sixeyed.com/published-ports-on-windows-containers-dont-do-loopback/

Sign up to request clarification or add additional context in comments.

Comments

5

Please post the docker command you are using.

You need an special treatment if you use Docker Toolbox or Docker for Windows. You should see localhost without problems (if your container is Linux). If you want your container be visible from outside, try this with Elevated Power Shell:

netsh interface portproxy add v4tov4 listenaddress=yourip listenport=9090 connectaddress=10.0.75.1 connectport=9090 

If your container is Windows however you won't see localhost and you need to use the container internal address:

docker inspect -f "{{ .NetworkSettings.Networks.nat.IPAddress }}" <cointainerid> 

Reference: https://www.docker.com/blog/build-your-first-docker-windows-server-container/

Regards

8 Comments

Hello Carlos, yes, I'm using latest docker for windows beta on win10 and docker info return "ServerVersion":"1.12.2-cs2-ws-beta" And according to Docker API v1.24 (docs.docker.com/engine/reference/api/docker_remote_api_v1.24/…) the PortBindings indeed exist.
You need extra port redirection for docker for Windows. I will update the answer
In fact I used docker inspect It explains the difference in nomenclature.
I dont think that it is the way. Do you have any official docs to support that answer? Why should I need a windows port forward if the other port is currently working? Also where did u saw fatal error? Also docker inspect return the same nomenclature, no difference.
Well my answer is based on: blog.docker.com/2016/09/… specially this part: To access the running app from the host running the containers (for example when running on Windows 10 or if opening browser on Windows Server 2016 system running Docker engine) use the container IP and port 5000. localhost will not work. I am assuming you are using Windows containers. They only thing we can do assume, because you don't post your docker command, dockerfile, even I asked for
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.