How to expose docker container’s ip and port to outside docker host without port mapping?

You can accomplish this with IP aliasing on the host.

First, add a virtual interface on the host that has a different IP address than the primary interface. We’ll call the primary interface eth0 with IP 10.0.0.10, and the virtual interface eth0:1 with IP address 10.0.0.11.

 ifconfig eth0:1 10.0.0.11 netmask 255.255.255.0 up 

Now run the containers and map port 5000 to the corresponding interface. For example:

docker run -p 10.0.0.10:5000:5000 -name container1 <someimage> <somecommand>
docker run -p 10.0.0.11:5000:5000 -name container2 <someimage> <somecommand>

Now you can access each container on port 5000 using different IP addresses externally.

Leave a Comment