Assign specific dockers only to specific ethernet port

I have multiple Ethernet connections to my server. Most all traffic uses the 10gb SFP connection. But I also have 2 other connections to 2.5gb ports (All are on different switches). I’m working to setup a VPN on my router assigned to a specific network. My goal is to assign certain docker images to use that interface instead of the normal interface.
From what I understand this should be possible. is there any guide on how to setup a dedicated network that can be assigned per docker image that can be assigned to say eth1 instead of eth3.

I could not find an official ZimaOS guide covering this specific setup.

What you are describing would normally require a Docker macvlan or ipvlan network, or policy-based routing, tied to the required Ethernet interface. However, the exact setup depends on the subnet, gateway, VPN routing, and whether the containers need individual LAN IP addresses.

Before providing commands, could you post:

ip -br address
ip route

Also confirm which interface connects to the VPN network and whether that interface has its own subnet and gateway.

eth0             UP             192.168.1.11/24
eth1             DOWN
eth2             UP             192.168.1.9/24
eth3             UP             192.168.1.10/24

I’ll probably put eth0 on the vpn, and it will have a new ip of 192.168.20.11 with a gateway of 192.168.20.1

I have not changed the IP/subnet yet, I’m waiting on a key piece of information from the vpn company I use. And was waiting on making sure I could do it on the ZimaOS side.

default via 192.168.1.1 dev eth3 proto static metric 100
default via 192.168.1.1 dev eth2 proto static metric 101
default via 192.168.1.1 dev eth0 proto static metric 102

All network interfaces are onboard. It is a WTR Max from Aoostar, even though ZimoOS thinks it a Zima device.

Your planned layout should support this once eth0 is moved to the VPN subnet:

eth0: 192.168.20.11/24
gateway: 192.168.20.1

The usual Docker approach would be a macvlan or ipvlan network using eth0 as the parent. Only the selected containers would be attached to that network and assigned addresses within 192.168.20.0/24. The remaining containers would continue using the normal Docker networks through eth3.

Before providing any exact configuration, please confirm:

  • Final VPN subnet and gateway
  • DHCP range on 192.168.20.0/24
  • An unused IP range reserved for Docker containers
  • Names of the containers to route through eth0
  • Whether those containers require direct access to the ZimaOS host
  • Whether the router and switch port permit multiple MAC addresses

Also avoid adding another competing host default route through eth0 unless that is intentional.

I could not find an official ZimaOS guide for this exact setup. It will likely need to be configured through Docker CLI or Compose after the final network details are confirmed.

I actually will need these apps to have the ability to save files on the system, and the docker images don’t need to be on the 20. network, they can be on internal space just like all the other dockers.
This is for torrent / newsgroup downloaders.

That changes the setup from what was originally described.

If the downloader containers can remain on their normal internal Docker network and only need outbound traffic routed through eth0, then macvlan may not be the correct approach. Their ability to save files through existing bind mounts is separate from which interface their internet traffic uses.

Before suggesting any configuration, we need the exact final requirements confirmed:

  • Which containers must use the VPN route
  • Whether only outbound internet traffic should use eth0
  • Whether local LAN access must remain available
  • Whether the containers must still communicate with other containers
  • Whether their existing /DATA or media mounts must remain unchanged
  • The final IP, subnet and gateway assigned to eth0

Once those requirements are clear, the correct Docker networking and routing method can be determined.

Macvlan is indeed what you’re looking for, and it’s a lot easier than it may seem in the first place :smiley:

All you have to do is create a network using the macvlan driver :

sudo docker network create \
        --driver macvlan \ # docker network driver to use
        --subnet 192.168.100.0/24 \ # subnet of docker host
        --gateway 192.168.100.1 \ # gateway for new network, same as docker host
        --opt parent=eth0 \ # parent interface on docket host
        your_macvlan # name of the macvlan network which you then use in your compose file

Then you can use this new network in your usual docker run command :

docker run -d \
  --name app \
  --network your_macvlan \
  --ip 192.168.100.50 \
  myapp

or your create it within your compose file and manually assign your container any ip you want :

services:
  app:
    image: app_image:latest
    networks:
      your_macvlan:
        ipv4_address: 192.168.100.50

  api:
    image: api_image:latest
    networks:
      your_macvlan:
        ipv4_address: 192.168.100.51

networks:
  your_macvlan:
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      config:
        - subnet: 192.168.100.0/24
          gateway: 192.168.100.1
          ip_range: 192.168.1.48/28  # Use this range for container IPs

Here’s the official documentation.