11

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?

errordeveloper
  • 6,716
  • 6
  • 41
  • 54
Manuel Durando
  • 1,493
  • 3
  • 19
  • 30
  • I'm not sure i understood your question. Are you trying to make multiple container speak to each other? – Regan Aug 20 '14 at 14:37
  • @Regan no, I'd like to assign an IP address to each container. These IPs are already configured on the network interface of the host machine. What I'd like to get is to have each container reachable at a specific IP address from outside the host machine. – Manuel Durando Aug 20 '14 at 14:39

2 Answers2

11

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).

Community
  • 1
  • 1
Manuel Durando
  • 1,493
  • 3
  • 19
  • 30
3

It's possible using the docker run --net command.

Official documentation : https://docs.docker.com/articles/networking/#how-docker-networks-a-container

First thing to do would be to create your own bridge using the official tutorial : https://docs.docker.com/articles/networking/#building-your-own-bridge

Or modify the existing one : https://docs.docker.com/articles/networking/#customizing-docker0

Then you will running your container will map his ip address into the table.

If you wanna be specific using the docker run --net=none command will let you configure your docker IP address.

Regan
  • 8,231
  • 5
  • 23
  • 23
  • Thanks for your reply. Can you please be a little more specific? I had already read the page, but I'm not sure about what I have to do. – Manuel Durando Aug 20 '14 at 14:52
  • Following the instruction in the link, if I'm not mistaken, I'm forced to use the IP class of the the bridge for the IP addresses of the containers: on my configuration I have different IP from different IP classes configured on the network interfaces of the host machine. Also I want that containers are reachable from outside the host machine, I'm not sure the instructions provided in the link solve my case. – Manuel Durando Aug 20 '14 at 15:00
  • You can modify the bridge. In fact it would probably be a better idea for your use case. – Regan Aug 20 '14 at 15:05
  • I already tried to modify the bridge and specify a public IP class. The problem is that the container is not reachable from outside, I can only expose a port and reach the container by `host_ip:exposed_port` and not by `container_ip:port` – Manuel Durando Aug 20 '14 at 15:23
  • @Reagan Thanks for you help, I found a solution: what I was looking for is [this](http://stackoverflow.com/questions/25036895/how-to-expose-docker-containers-ip-and-port-to-outside-docker-host-without-port) – Manuel Durando Aug 20 '14 at 21:27