'Assigning /32 ip addr to containers with docker compose Ubuntu 20.04

as you might quickly notice, I'm not a network nor a docker guru. I appreciate all help big time!

I'm trying to run a two applications in two different docker container using docker-compose. I managed to run 1 application using the host network. Great success, at least for half of my goal. Every container needs to be mapped to a specific IP address. If you wonder why, it's because the services in the containers will be accessed by other applications on the www on a specific port. But every container uses the same port for this communication. To give you a more visual idea of the desired setup, here's a visual:

required network setup

For service A I linked the container to the host network. My the docker-compose.yml looks like this:

version: "3.8"
services:
  shell:
    image: "${MAIN_IMAGE}"
    container_name: mnm_shell
    network_mode: host
    pid: host
    volumes:
      - "mnms:/home/mnms"
    entrypoint: [ "bash" ]
    env_file:
      - "./.env"

After lots of research I found many articles describing how to make a macvlan with a private address subnet but I did not find any article describing how to link one (or more) /32 networks to specific containers.

Any help, guidance, examples are welcome. Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source