version: "3" services: prometheus: image: prom/prometheus:latest container_name: prometheus ports: - "9090:9090" volumes: - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml - ./prometheus/alert_rules.yml:/etc/prometheus/alert_rules.yml command: - "--config.file=/etc/prometheus/prometheus.yml" - "--web.enable-lifecycle" # 允许通过 API 重新加载配置 networks: - monitoring grafana: image: grafana/grafana:latest container_name: grafana ports: - "3100:3000" volumes: - ./grafana/grafana.ini:/etc/grafana/grafana.ini # 可选:自定义 Grafana 配置 networks: - monitoring depends_on: - prometheus node-exporter: # 示例:部署 Node Exporter 监控本机 image: prom/node-exporter:latest container_name: node-exporter ports: - "9100:9100" networks: - monitoring networks: monitoring: driver: bridge