Use MacVLAN and obtain domain automatically

This commit is contained in:
Colin Hebert
2023-01-03 19:45:45 +01:00
parent 93d594dd02
commit 98aa775ff7
4 changed files with 30 additions and 2 deletions

View File

@@ -22,6 +22,9 @@ services:
networks: networks:
- traefik - traefik
- docker - docker
- macvlan
environment:
- NAS_COMPOSE_DOMAIN=${NAS_COMPOSE_DOMAIN?}
# TODO: Move to configs? # TODO: Move to configs?
volumes: volumes:
- traefik_dynamic_config:/etc/traefik/dynamic/:ro - traefik_dynamic_config:/etc/traefik/dynamic/:ro
@@ -69,6 +72,8 @@ networks:
name: traefik name: traefik
labels: labels:
nas-compose.boostrap: true nas-compose.boostrap: true
macvlan:
external: true
volumes: volumes:
portainer_data: portainer_data:

View File

@@ -1,5 +1,28 @@
# Bootstrap # Bootstrap
Set up a MacVLAN network
As an example, with the following network setup:
- interface to LAN: `bond0`
- Complete LAN subnet: `192.168.0.0/23`
- LAN gateway: `192.168.0.1`
- DHCP range: `192.168.0.0/24` (excluding gateway)
- MacVLAN interface name: `macvlan0` (user defined)
- MacVLAN range: `192.168.1.0/24` (should be outside of DHCP range)
- MacVLAN host IP: `192.168.1.1` (should be in the MacVLAN range)
```
docker network create -d macvlan -o parent=bond0 --subnet=192.168.0.0/23 --gateway=192.168.0.1 --ip-range=192.168.1.0/24 --aux-address "nas=192.168.1.1" macvlan
ip link add macvlan0 link bond0 type macvlan mode bridge
ip addr add 192.168.1.1/32 dev macvlan0
ip link set macvlan0 up
```
Run portainer once
```
docker run --rm -p 9443:9443 -v /var/run/docker.sock:/var/run/docker.sock portainer/portainer-ce:latest
```
### Environment variables ### Environment variables
- `SERVICES_DIR`: Absolute path to the `services` folder - `SERVICES_DIR`: Absolute path to the `services` folder

View File

@@ -3,7 +3,7 @@ providers:
endpoint: tcp://docker:2375 endpoint: tcp://docker:2375
exposedByDefault: false exposedByDefault: false
network: traefik network: traefik
defaultRule: Host(`{{ index .Labels "com.docker.compose.service" }}.dev.dedicated.contact`) defaultRule: Host(`{{ index .Labels "com.docker.compose.service" }}.{{ env `NAS_COMPOSE_DOMAIN` }}`)
file: file:
directory: /etc/traefik/dynamic/ directory: /etc/traefik/dynamic/

View File

@@ -1,7 +1,7 @@
http: http:
routers: routers:
traefik: traefik:
rule: Host(`traefik.dev.dedicated.contact`) rule: Host(`traefik.{{ env `NAS_COMPOSE_DOMAIN` }}`)
service: api@internal service: api@internal
middlewares: middlewares:
- traefik-auth - traefik-auth