Answer the question
In order to leave comments, you need to log in
How to create a network attached to a vlan interface in docker compose?
There are several vlan interfaces: eth0.10, eth0.20, eth0.30.
Each vlan has its own gateway with different external ip.
It is necessary for different services in docker compose to issue different networks tied to vlan so that each service has its own gateway from vlan. Show an example of how this should be configured using 2x nginx as an example.
It is the gateway that is needed (so that outgoing requests from the container go through the specified vlan), port forwarding works on ports: "10.10.10.2:80:80", where 10.10.10.2 is the address on the vlan interface.
Answer the question
In order to leave comments, you need to log in
You need to use the macvlan network driver for docker. Here is a very good example
https://github.com/sarunas-zilinskas/docker-compos...
---
version: '2.4'
services:
portainer:
image: portainer/portainer
container_name: portainer
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /path/to/data:/data
ports:
- 8000:8000
- 9000:9000
networks:
vlan:
ipv4_address: 192.168.0.60
networks:
dockervlan:
#This interface should be defined as using null driver. Do not remove it.
driver: null
driver_opts:
parent: eth0
ipam:
config:
- subnet: "192.168.0.0/24"
ip_range: "192.168.0.64/26"
gateway: "192.168.0.1"
dockervlan:
#This is the interface which is used for containers networking
driver: macvlan
driver_opts:
parent: eth0
ipam:
config:
- subnet: "192.168.0.0/24"
ip_range: "192.168.0.64/26"
gateway: "192.168.0.1"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question