Several public IP on one ethernet interface, several containers per public IP

I need to organize networking for Docker containers. I have a host with several public IP on the same physical interface: enp1s0:, let them be 987.654.321.1, 987.654.321.2, 987.654.321.3, 987.654.321.4, 987.654.321.5 :slight_smile:

What do I need:

[Project 1, container 1]--|
[Project 2, container 1]--|--987.654.321.1
[Project 3, container 1]--|

[Project 1, container 2]--|
[Project 2, container 2]--|--987.654.321.2
[Project 3, container 2]--|

[Project 1, container 3]--|
[Project 2, container 3]--|--987.654.321.3
[Project 3, container 3]--|

so, all containers will access world through corresponding public IP.

I have an experience with LXD/LXC. In LXD I would do the next:

#!/usr/bin/env bash
PUBLIC_IP_LAST_NUMBER=1
until [[ "${PUBLIC_IP_LAST_NUMBER}" == "6" ]]; do
  PUBLIC_IP="987.654.321.${PUBLIC_IP_LAST_NUMBER}"
  # Let each network have the same name, as corresponding IP. Why not?
  NETWORK_NAME="${PUBLIC_IP}"
  lxc network create ${NETWORK_NAME} --type=bridge
  lxc network set ${NETWORK_NAME} ipv4.nat.address=${PUBLIC_IP}
  for PROJECT in alpha beta gamma; do
    CONTAINER_NAME="${PROJECT}-${PUBLIC_IP_LAST_NUMBER}"
    lxc launch ubuntu:20.04 ${CONTAINER_NAME}
    lxc config device override ${CONTAINER_NAME} eth0 type=nic network=${NETWORK_NAME}
  done
  let PUBLIC_IP_LAST_NUMBER="(${PUBLIC_IP_LAST_NUMBER} + 1)"
done

But how to do the same in Docker?

Give me, please, a piece of advice.