Docker container with ip address on local network, p2

In my latest post I described described a way to give a docker container an address on the local network. That’s a general way of achieving it, but it’s also rather complicated. If you know exactly what ports need to be exposed there is a simpler way.

Add a second IP to the system interface

There’s a good description on how to give an interface multiple in Debian at the Debian Wiki. The completely manual way is

ip addr add 192.168.1.199/24 dev eth0 label eth0:0

The configuration in Debian is

auto eth0:0
iface eth0:0 inet static
  address 192.168.1.199
  netmask 255.255.255.0

If you’re using Systemd it seems to be enough to just add extra Address=... statements to the .network file:

[Match]
Name=eth0

[Network]
Address=192.168.1.2/24
Address=192.168.1.199/24
Gateway=192.168.1.1

Bind ports of the container to a specific IP

Using the image from my latest post it’s just to run it using the --publish option:

docker --rm --interactive --tty --name=echo --publish=192.168.1.199:2048:2048 nw /home/myusre/echosrv

Just like the last time it’s easy to verify everything’s working using netcat.

⟸ Docker container with ip address on local network How can I unit test failure cases? ⟹
Leave a comment