1.docker-compose.yml配置如下
version: '3.9'
networks:
monitor:
driver: bridge
services:
prometheus:
image: prom/prometheus:v2.28.1
container_name: prometheus_gpe
hostname: prometheus
restart: always
volumes:
- /data/gpe/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- /data/gpe/prometheus/data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
ports:
- "9090:9090"
networks:
- monitor
alertmanager:
image: prom/alertmanager:v0.22.2
container_name: alertmanager_gpe
hostname: alertmanager
restart: always
volumes:
- /data/gpe/alertmanager/alertmanager.yml:/etc/alertmanager/alertmanager.yml
ports:
- "9093:9093"
networks:
- monitor
grafana:
image: grafana/grafana:8.0.6
container_name: grafana_gpe
hostname: grafana
restart: always
volumes:
- /data/gpe/grafana/data:/var/lib/grafana
ports:
- "3001:3000"
networks:
- monitor
2.我这里挂载了prometheus.yml和alertmanager.yml,这两个文件直接docker启动prometheus和alertmanager然后使用容器复制命令复制出来
docker cp 容器id:/etc/prometheus/prometheus.yml /data/gpe/alertmanager
3.启动如过报权限不足,则对prometheus和grafana的data目录加777权限
chmod 777 /data/gpe/grafana/data
4.docker-compose up -d 进行启动