0

I have a docker container running on a Centos host and has a host port: container port mapping. The docker container has an web application running.

CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS                            NAMES
a2f8ce62bb69        image1                 "/bin/bash"         16 hours ago        Up 16 hours         22/tcp, 0.0.0.0:7001->7001/tcp   nostalgic_elion

I can access the application over http by host IP address and host port which is mapped. However if I replace the host IP with container IP, then I get an error saying "site cannot be reached" ERR_CONNECTION_TIMED_OUT.

Is it possible to access using the container IP and exposed port over http? Unfortunately I do not have much background on networking.

Matt
  • 68,711
  • 7
  • 155
  • 158
user1470220
  • 123
  • 2
  • 15
  • If you go to your host IP:7001 it will redirect your to your container IP:7001. You can only access the container IP (internal ip) from inside your centos host. curl container-ip:7001 – lvthillo Jun 09 '16 at 08:41
  • It is not redirecting to container IP. The issue is not with accessing the application running in the container. But I want to access the application using container's IP. Is this not possible? – user1470220 Jun 09 '16 at 08:47
  • The IP of your container (172...) is an IP which isn't accessible from the outside. So you're able to access it if you have a UI for your centos with a browser : 172.xx:7001. But when your using a real server without UI you have to youse thepublic ip of your server:7001 to access your app from a browser which isn't inside your centos server – lvthillo Jun 09 '16 at 08:51

2 Answers2

0

By default Docker containers can make connections to the outside world, but the outside world cannot connect to containers. (https://docs.docker.com/v1.7/articles/networking/)

The docs however, say it is possible to have outside world talk to containers with some extra run options. The docs say about using the run with options -P or ----publish-all=true|false. Refer the options in the same docker networking page.

sandy
  • 25
  • 8
  • I have seen the documentation and hence ran the container with -p host_port:container_port. My question is more around IP address of container. lorenzvth7 correctly mentioned that container's ip address is visible from outside. Any ideas on how to make it visisble? As i mentioned I do not have much background in networking. – user1470220 Jun 09 '16 at 09:02
  • Why do you want to do this when you're able to access and configure everything by using the ip-of-your-host:port (or internally private-ip:port). – lvthillo Jun 09 '16 at 09:12
  • Each docker container runs a set of applications. Now when the endpoints is shared with other teams, there is a confusion of same host name. Since each container has separate ip address assigned, hence I wanted to use the ip address to access the application from outside – user1470220 Jun 09 '16 at 09:15
  • as explained more in detail here http://stackoverflow.com/questions/25036895/how-to-expose-docker-containers-ip-and-port-to-outside-docker-host-without-port/25041782#25041782 you can workaround it with IP aliasing on the host and adding to the -p option the ip binding -p ip-alias:port:container-Port – Zeromus Jun 09 '16 at 13:35
0

If your only need is to share different ip address to teams. update your host file with the docker containers ip address - localhost

My /etc/hosts file:

container-ip   localhost
container-ip   localhost
container-ip   localhost