示例

如下是为容器设置固定IP的 ​​docker-compose.yml​​​ 示例,其中包含定义 ​​networks​​ 和在应用中引用设定固定 IP 的配置。

version: '3.9'
services:

coredns:
image: coredns/coredns:1.10.0
container_name: coredns
ports:
- 53:53/udp
networks:
mynetwork:
ipv4_address: 172.28.0.4
volumes:
- ./coredns/hostsfile:/etc/coredns/hostsfile
- ./coredns/Corefile:/Corefile

networks:
mynetwork:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.28.0.0/16
gateway: 172.28.0.1

参考官网链接:


(END)