docker默认网段是172.17,和公司的网段172.16和172.18有时候会冲突,解决方法就是换docker网段。
方案:不改docker网段,创建不和公司网段冲突的docker子网段
1docker network create --driver=bridge --subnet=172.19.0.0/24 monitor_net
运行容器时指定
1docker run -it --name <容器名> ---network monitor_net <镜像名>
在docker-compose同样通过networks指定,形式如下:
1version: '3'
2networks:
3 monitor:
4 #使用已经存在的网络
5 external:
6 name: monitor_net
7
8services:
9 prometheus:
10 image: prom/prometheus
11 container_name: prometheus
12 hostname: prometheus
13 privileged: true
14 restart: always
15 volumes:
16 - /usr/local/src/config/prometheus.yml:/etc/prometheus/prometheus.yml
17 - /usr/local/src/config/node_down.yml:/etc/prometheus/node_down.yml
18 ports:
19 - "9091:9090"
20 networks:
21 - monitor
22 links:
23 - alertmanager
24 - node-exporter