How to get different ip address to each container?

Hi. My English is not very good. I’m sorry for that. I will try to explain my problem as much as possible.

I have a dedicated server

example to my dedicated server ip setting:
IP: 31.x.x.90/94
SUB: 255.x.255.248
GW: 31.x.x.89

ALTERNATIVE IP: 31.x.x.91/94
ALTERNATIVE IP: 31.x.x.92/94
ALTERNATIVE IP: 31.x.x.93/94
ALTERNATIVE IP: 31.x.x.94/94

My problem : I want to give different public static ip for each container. How can I do that?

Each container give the same ip address (31.x.x.90)
but I want it to give different (example : container1 = 31.x.x.91 , container2 = 31.x.x.92)

I was route all ip addresses to my server.

I tried to use macvlan,bridge etc. but it doesn’t accept this subnet (similar to 255.255.255.x)

Is there a way to solve this problem?
Thank you in advance for your help!

-to create static ip, you need to create you own docker network (mynet123)

docker network create --subnet= mynet123

then simply run the image (I’ll take ubuntu as example)

docker run --net mynet123 --ip -it ubuntu bash

then in ubuntu shell

ip addr

Additionally you could use

  • –hostname to specify a hostname

  • –add-host to add more entries to /etc/hosts

Docs (and why you need to create a network) at

1 Like