Score:0

Is it possible to assign different external IP addresses to different Docker containers running on the same server?

cn flag

Let it be 3 machines on the network (192.168.1.1/24):

  1. Server running Docker with 2 containers C1 and C2 (192.168.1.3)
  2. Personal Computer 1 PC1 (192.168.1.4)
  3. Personal Computer 2 PC2 (192.168.1.5)

C1 and C2 are serving a static website on tcp port 80 (C1) and 81 (C2) on the IP 192.168.1.3.

Is it possible to assign two different IPs to the containers? Let's say for example 192.168.1.6:80 for C1 and 192.168.1.7:80 for C2

Score:0
in flag

Sure.

docker run -p 192.168.1.6:80:80 --name C1 c1
docker run -p 192.168.1.7:80:80 --name C2 c2

You can bind a port to any IP configured on the host.

Fabio Rovati avatar
cn flag
Thank you! Do I need multiple network interfaces (aka. cards) to configure multiple IPs to a single machine?
in flag
You can configure as many IP addresses as you want on a single physical NIC.
Fabio Rovati avatar
cn flag
Do you happen to have a link or anything detailing the procedure to follow to configure multiple IPs on a Ubuntu machine?
in flag
[Sure, go ahead](https://www.google.com/search?q=ubuntu+20.04+multiple+ip+addresses+on+one+interface)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.