Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure a Docker container to be reachable by container_ip:port from outside the host machine?

I have a host machine with multiple IP addresses assigned to one network interface. I'd like to configure Docker in order to have containers "responding" each one to a single IP of these IP addresses assigned to the host machine.

Can this be done with libcontainer or do I have to use the LXC driver and run my containers with --lxc-conf="lxc.network..."?

Thanks in advance.

UPDATE

I want each container to be reachable from outside; with the default Docker configuration I can only expose a port and reach the container by host_ip:exposed_port and not by container_ip:port. Can this second option be configured in some way?

like image 910
Manuel Durando Avatar asked Aug 20 '14 14:08

Manuel Durando


People also ask

How do I get to Docker container from outside?

By default, when you create or run a container using docker create or docker run , it does not publish any of its ports to the outside world. To make a port available to services outside of Docker, or to Docker containers which are not connected to the container's network, use the --publish or -p flag.

Can Docker container connect to outside world?

Your Docker container can connect to the outside world, but the outside world cannot connect to the container. To make the ports accessible for external use or with other containers not on the same network, you will have to use the -P (publish all available ports) or -p (publish specific ports) flag.


1 Answers

This answer explain exactly what I want to obtain in a very simple way.

The idea is to have different IP addresses on the host machine, for example using IP aliasing on a single network interface and then launch each container specifying the IP address to where they will be reachable in addition to the exposed port (see the linked answer for an example).

like image 155
Manuel Durando Avatar answered Oct 03 '22 19:10

Manuel Durando