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

2

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?

Extrados answered 20/8, 2014 at 14:31 Comment(2)
I'm not sure i understood your question. Are you trying to make multiple container speak to each other?Inexpugnable
@Inexpugnable 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.Extrados
E
12

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

Extrados answered 20/8, 2014 at 21:25 Comment(0)
I
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.

Inexpugnable answered 20/8, 2014 at 14:48 Comment(5)
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.Extrados
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.Extrados
You can modify the bridge. In fact it would probably be a better idea for your use case.Inexpugnable
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:portExtrados
@Reagan Thanks for you help, I found a solution: what I was looking for is thisExtrados

© 2022 - 2024 — McMap. All rights reserved.