How to configure a Docker container to be reachabl

2019-02-09 04:13发布

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?

2条回答
forever°为你锁心
2楼-- · 2019-02-09 04:31

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

查看更多
三岁会撩人
3楼-- · 2019-02-09 04:33

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.

查看更多
登录 后发表回答