Docker Community Forums

Share and learn in the Docker community.

Why are exposed ports not open on host?

(Littlesandra88) #1

If I set up a webserver like so

docker run --name landing -v /docker/landing:/usr/share/nginx/html:ro -d -p 10000:80 nginx

which have the ip and do

# curl -i            
curl: (7) Failed to connect to port 10000: Connection refused

If I access the public IP of the host with when it works.

Is there a way to make the ports available on the Docker host and the other containers without linking them?

(Jeff Anderson) #2


the -p 10000:80 option will set up a port forward. port 10000 on the host will forward to port 80 on the container. The ip address looks like it is the ip address of the container, not the host. I would expect that you can use port 10000 on any host ip address, including the host’s

Normally if you want to access a container’s service from the host or outside the host, you will want to use the port publishing feature, and connect to the published port, not the container’s IP.

If you want to connect to a container from another container, --link helps make it easy to resolve the ip and figure out what port to make the connection on.

Additionally, if you have containers connected to a docker network create custom network, they can find eachother by name.

For example:

docker network create test
docker run --name webtest --net=test -d nginx:alpine
docker run --rm -it --net=test alpine ping -c 1 webtest
PING webtest ( 56 data bytes
64 bytes from seq=0 ttl=64 time=0.142 ms

--- webtest ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.142/0.142/0.142 ms

(Littlesandra88) #3

Thanks a lot. localhost:10000 works perfectly =)

Your net example is very interesting! That is just what I am looking for the nginx reverse proxy I am trying for set up =)