Docker containers hosted on Raspberry Pi on vlan
It was at first a bit tricky to figure out what to use to effectively run docker containers on a vlan. My host device is a Raspberry Pi 4 that is on the vlan that I want to use.
Raspberry Pi configuration
The raspberry pi's ethernet adaptor needs to be set to use predictable
interface names, this is done using
> sudo raspi-config
6 Advanced Options
A4 Network Interface Names
- Reboot when asked.
docker-compose.yaml will need to have the following initial configuration.
You will need to change the addresses as required. My vlan is
version: '3.8' networks: vlan: driver: ipvlan driver_opts: parent: eth0 ipam: config: - subnet: 192.168.5.0/24 gateway: 192.168.5.1 ip_range: 192.168.5.100/25 backend:
Backend is included for inter-container communications:
Containers are now capable of existing on the
backend or both networks.
The containers are configured as per this example.
!! note "docker-compose.yaml"
version: '3.8' networks: vlan: driver: ipvlan driver_opts: parent: eth0 ipam: config: - subnet: 192.168.5.0/24 gateway: 192.168.5.1 ip_range: 192.168.5.100/25 backend: services: caddy: image: caddy:2-alpine hostname: caddy container_name: caddy restart: unless-stopped networks: vlan: ipv4_address: 192.168.5.30 backend: ports: - "80:80" - "443:443" - "2019:2019" - "32500:32500" dns: - 192.168.5.23 - 192.168.1.1 # configuration has been abbreviated. unbound: image: klutchell/unbound container_name: unbound ports: - '5053:5053/udp' networks: backend: vlan: ipv4_address: 192.168.5.24 restart: unless-stopped pihole: container_name: pihole image: pihole/pihole:latest hostname: pi-hole ports: - "53:53/tcp" - "53:53/udp" - "67:67/udp" - "80:80/tcp" - "443:443/tcp" environment: - TZ=Pacific/Auckland - VIRTUAL_HOST=www.someplace.nz networks: backend: vlan: ipv4_address: 192.168.5.23 restart: unless-stopped
Note that above I have listed the exported ports, this is not necessary on the vlan as the ports are exported in the image configurations. This is just for show.
This should be enough to get going. More than one server can run containers on the same subnet as well.