brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: a macvlan network puts a Docker container straight on your LAN

Docker
~/tips/tip-docker-macvlan-network

docker network create -d macvlan \

Give a container its own address and MAC on the physical network.

Pi-hole, Home Assistant and some media servers work best when they look like a separate device on the network. A macvlan network gives a container its own MAC address and an IP from your LAN.

docker network create -d macvlan \
  --subnet 192.0.2.0/24 --gateway 192.0.2.1 \
  --ip-range 192.0.2.192/27 \
  -o parent=eth0 lan

docker run -d --name pihole --network lan --ip 192.0.2.200 example/pihole:1.0

Use your own LAN’s subnet and gateway, and the name of the host’s network card as parent. The --ip-range keeps Docker inside a block your router’s DHCP does not hand out, which I would also reserve in the router.

No port publishing is needed; the container answers on all its ports at its own address, just like another machine on the network.

The host itself cannot talk to its macvlan containers by default. The Linux kernel blocks traffic between the parent interface and its macvlan children, so a container on the host network or the host’s own shell cannot reach the Pi-hole. The usual workaround is a small macvlan interface on the host. Wi-Fi interfaces and many virtual machine setups refuse extra MAC addresses, so macvlan works best on a wired network card. Unraid users who see call traces can switch to ipvlan.

Further reading: Macvlan network driver

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link