Using Hetzner Additional IPv4 Subnet with Docker

Hi! Wondering if someone could point me in the right direction.

I have a Hetzner AX102 Ubuntu 22.04 server and i’ve added an additional IPv4 /24 subnet and I’m having trouble getting docker containers to work correctly.

So for this post:

Original ip address is 65.x.x.29/32

Additional subnet is 32.x.x.0/24

My requirement is to have say 8 docker containers each be assigned its own IP from the additional subnet and have an inbound port mapping. Containers need outbound connectivity.

So for example docker container 2 receives IP address say 32.x.x.2, then map (publish) inbound listen port 32.x.x.2:20000:20000

I’ve followed Hetzner Additional IP documentation by adding additional IP addresses as /32 to the enp6s0 interface directly via netplan.

I create a bridge docker network for the subnet 32.x.x.0, which automatically assigns 32.x.x.1 as the gateway for the subnet (in docker network)

Then i create a container something like docker run -itd --name=c1 --ip=32.x.x.1 --network=subnet1 -publish 32.x.x.1:20000:20000 image

When using netplan, this partially works, the container correctly maps the inbound port 20000 to 32.x.x.2

Under this configuration the container uses 32.x.x.1 as the gateway but outbound traffic does not work at all, since it seems the container can’t get to the eth ip address and to the eth ip gateway.

Based on all the research i’ve done, i’m seeing several options

a) fix some missing config in netplan, maybe i’m missing a route statement on the host. Adding routes to container does not work, cant really add routes to the docker network

b) use /etc/network/interfaces (ENI) instead of netplan, using ifupdown is deprecated

c) use host virtual bridge, virbr0, for the subnet, routing or bridged. The issue here is that you cannot specify a modified container (guest) network configuration.

d) use pointtopoint on ENI? using ifupdown is deprecated

e) is there some docker network config? macvlan, ipvlan?

f) ive seen a post about sending DefaultIPv4Gateway via aux-address

The problem is there seem like there are so many different options and so many configuration suggestions, making this hard to troubleshoot and track down the solution.

Any insight appreciated!

You want all the containers to be available externally? Why not use a simple -p 32.x.x.1:20000:20000 without a dedicated bridge network?

that worked…thank you!

Occom’s Razor at its finest…


I had to look that up :rofl: