Multiple host ips to docker container

Hello everyone,

I know that I can map a specific port from the host to the container and assign the ip address at the same time. I am not sure this is possible to do but I would like to map a 1 to 1 ip address from the host to a container. E.g. Host IP 192.168.56.50 all ports to a container 172.17.0.9 all ports. Is this possible to do? Any suggestions would be greatly appreciated.

1 Like

When you publish a port, you can specify an IP address to bind to. This means that I can add multiple IP addresses to my docker host, and specify each IP as I create/run the containers:

docker run -d -p 192.168.56.50:80:80 nginx

This would bind the nginx container’s port 80 to port 80 on 192.168.56.50.

It is also possible to specify a range of ports when you publish them:

docker run -d -p 100-200:100-200 nginx

And you can indeed combine the syntaxes:

docker run -d -p 192.168.56.50:100-200:100-200

One thing to keep in mind, is that docker does fire up one docker-proxy process per port that is mapped. Mapping all ports would cause a lot of processes to be started on your host system. You can disable the userland proxy setting in favor of a NAT implementation: https://docs.docker.com/articles/networking/

/Jeff

Jeff,

Thank you for the information. That is exactly what I am looking for. I will keep an eye on the docker-proxies. Although NATing maybe a better solution as there will be a one to one relationship between the host ip and docker container. Again much appreciated.

Craig