How do I configure Docker containers to have unique IP addresses that are not the default ones?

The Docker containers will run Apache or some web service. These Docker containers will share one host that has one physical NIC. These containers must be identifiable by unique IP addresses with calls over port 80. Workstations will use HTTP to download files.

I tried creating dummy IP addresses on the Docker host. But this caused networking to the server to drop.

I tried installing Docker overlay, but I don't think it will help me with getting workstations to use HTTP requests to the containers. Docker overlay appears to be geared toward inter-container connectivity.

I looked into using interlock, but I'd rather not use Swarm.


The easiest solution here is to add additional addresses to the host, and then bind one container to each address. For example, assuming that your host is, you could add additional addresses like this:

ip addr add dev eth0
ip addr add dev eth0
ip addr add dev eth0

And then, when starting a container, publish port 80 in the container to port 80 on a particular host address, like this:

docker run -p mywebimage

(This doesn't change the ip address of the container; it creates a map between the given ip address and port and the container's internal ip address and port.)

Note that the address configuration shown here will not be persistent; if you reboot your host you will lose the addresses. Exactly how you configure addresses like this persistently varies from distribution to distribution; refer to your distribution documentation for details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.