I am trying to deploy a stack in my docker swarm which has an IP on my local network. I’m given to understand a macvlan can do this but when I create one and deploy my service, the macvlan appears to have disregarded the subnet and gateway I have provided and creates a random new subnet in the 172.x.x.x range. Understandably my container cannot communicate with my local network.
For arguments sake we’ll say my local network is 192.168.1.0/24 and my gateway is 192.168.1.1 and my hosts are both using eth0.
I am using docker network create -d macvlan --subnet 10.155.5.0/24 --gateway 10.155.5.1 --ip-range=10.155.5.210/32 --scope swarm -o parent=eth0 priv_lan
to create my network.
I am using the following compose file to deploy the stack
services:
cloudflared:
image: crazymax/cloudflared:latest
command: proxy-dns
environment:
UPSTREAM1: "https://1.1.1.1/dns-query,https://1.0.0.1/dns-query,https://9.9.9.9/dns-query,https://149.112.112.9/dns-query"
PORT: "5053"
TUNNEL_DNS_UPSTREAM: "https://1.1.1.1/dns-query,https://1.0.0.1/dns-query,https://9.9.9.9/dns-query,https://149.112.112.9/dns-query"
TUNNEL_DNS_PORT: 5053
TUNNEL_DNS_ADDRESS: "0.0.0.0"
networks:
internal:
ipv4_address: 172.30.9.2
pihole:
image: pihole/pihole:latest
environment:
TZ: 'Europe/London'
WEBPASSWORD: ${WEBPASSWORD}
DNS1: '172.30.9.2#5053'
DNS2: 'no'
DNSMASQ_LISTENING: 'all'
volumes:
- 'pihole:/etc/pihole'
- 'dnsmasq:/etc/dnsmasq.d'
networks:
internal:
ipv4_address: 172.30.9.3
priv_lan:
ipv4_address: 192.168.1.200
deploy:
mode: replicated
replicas: 1
placement:
constraints: [node.platform.os == linux]
depends_on:
- cloudflared
networks:
internal:
ipam:
config:
- subnet: 172.30.9.0/29
priv_lan:
external:
name: priv_lan
volumes:
pihole:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/data/gluster/gluster_volume0/pihole'
dnsmasq:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/data/gluster/gluster_volume0/dnsmasq'
The services/containers deploy successfully but priv_lan appears to have a subnet of 172.20.0.0/16, a gateway of 172.20.0.1 and the pihole container has an IP of 172.20.0.2. (The second octet appears to increment with each deployment.
Does anyone know why this might be? I am at a loss. I’ve scoured the internet to no avail and am at a complete loss.