Build docker environment migrate from Virtualbox with complex network configuration

The first three questions you asked are solved with macvlan network. You'll have containers directly attached to your network, just like VM's. Here's an example:

version: "2.1"

services:
  nginx1:
    image: nginx
    networks:
      network_1:
        ipv4_address: 10.1.1.115
  nginx2:
    image: nginx
    networks:
      network_1:
        ipv4_address: 10.1.1.116


networks:
  network_1:
    driver: macvlan
    driver_opts:
      parent: enp52s0  # Your network interface name
    ipam:
      driver: default
      config:
        - subnet: 10.1.1.0/24
          gateway: 10.1.1.1

In this example I declared a macvlan network named network_1, which attached to the enp52s0 network interface. The two nginx containers use that network and each advertises its own static IP.

Now if you want to assign more than one IP per container things begin to get messy. To assign an additional address you need an additional network, with its own IP range, its own parent network interface, and its own gateway. That is literally another network. Or you can think of some hack, maybe using a proxy container that'll listen on another IP and forward traffic into desired container but it's kinda 'meh'. I'd say that VM overhead does not worth all that trouble unless you are open to redesign connectivity of your application.

Tags:

Docker