- 自定义网络 - HOST
与宿主机共享网络
version: "3"
services:web:image: nginx:1.21.6restart: alwaysports:- 80:80network_mode: host
-
自定义网络 - 固定ip
version: "3" services:web:image: nginx:1.21.6restart: alwaysports:- 80:80networks:app:ipv4_address: 172.20.0.2 networks:app:driver: bridgeipam:config:- subnet: 172.20.0.0/16gateway: 172.20.0.1
- 自定义网络 - 指定网段
version: "3" services:web:image: nginx:1.21.6restart: alwaysports:- 80:80networks:- app networks:app:driver: bridgeipam:config:- subnet: 172.20.0.0/16gateway: 172.20.0.1