Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jeff47/04c408cb123b7b9c2977cc0694fd5162 to your computer and use it in GitHub Desktop.

Select an option

Save jeff47/04c408cb123b7b9c2977cc0694fd5162 to your computer and use it in GitHub Desktop.
Raspberry Pi Docker + macvlan Restoration Workflow

Raspberry Pi Docker + macvlan Restoration Workflow

1. Install required packages

sudo apt update
sudo apt install -y docker.io docker-compose network-manager dnsutils
sudo systemctl enable docker NetworkManager
sudo systemctl start docker NetworkManager

2. Configure static IP for the host (eth0)

nmcli con add type ethernet ifname eth0 con-name eth0-static \
   ipv4.addresses 192.168.1.20/24 ipv4.gateway 192.168.1.1 ipv4.method manual
nmcli con up eth0-static

Verify:

nmcli device status
ip addr show eth0
ip route show

3. Create macvlan-lan interface

sudo nmcli con add type macvlan ifname macvlan-lan con-name macvlan-lan \ 
   dev eth0 mode bridge ipv4.addresses 192.168.1.23/32 ipv4.method manual

Add static routes for containers:

sudo nmcli con modify macvlan-lan +ipv4.routes "192.168.1.21/32"
sudo nmcli con modify macvlan-lan +ipv4.routes "192.168.1.22/32"
sudo nmcli con modify macvlan-lan +ipv4.routes "192.168.1.23/32"

Bring interface up:

sudo nmcli con up macvlan-lan

Verify:

nmcli device status
ip addr show macvlan-lan
ip route show

4. Restore Docker volumes

Copy your Pi-hole and other container volumes:

${HOME}/pihole/pihole
${HOME}/kidspi/pihole

Ensure correct permissions: (verify PID and GID for your system)

sudo chown -R 1001:995 ${HOME}/pihole
sudo chown -R 1001:995 ${HOME}/kidspi

5. Restore Docker Compose

Place your docker-compose.yml in a directory. Make sure:

  • macvlan-lan is external
  • Containers have fixed IPs (192.168.1.21 / .22)
  • ports: mappings for macvlan containers can be removed

6. Start containers

docker compose up -d

Verify:

docker ps
docker logs pihole
docker logs kidspi

Test connectivity:

ping -c 2 192.168.1.21
ping -c 2 192.168.1.22
dig @192.168.1.21 google.com
dig @192.168.1.22 google.com

7. Optional: Backup NetworkManager connections

Export connections so future restores are faster:

nmcli connection export eth0-static eth0-static.nmconnection
nmcli connection export macvlan-lan macvlan-lan.nmconnection

Restore with:

nmcli connection import type ethernet file eth0-static.nmconnection
nmcli connection import type macvlan file macvlan-lan.nmconnection
nmcli con up eth0-static
nmcli con up macvlan-lan

This workflow:

  • Stops after each step so you can verify success
  • Uses only packages in a vanilla install (no dhcpcd or ifupdown)
  • Ensures your Pi-hole containers keep the same IPs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment