1.docker-compose部署需要xxx.yml文件

xxx.yml文件配置如下:

version: '3.7'
services:
  node-exporter:
    image: prom/node-exporter:latest
    hostname: node-exporter
    container_name: node-exporter
    ports:
      - "9100:9100"
    depends_on:
      - prometheus
    networks:
      - prom
  prometheus:
    image: prom/prometheus:latest
    hostname: prometheus
    container_name: prometheus
    volumes:
      - /opt/dmgeo/prom/prometheus/data:/opt/data/docker/volumes/config2_prometheus/_data
      - type: bind
        source: /opt/pgn/config2/prometheus.yml
        target: /etc/prometheus/prometheus.yml
        read_only: true
      - type: volume
        source: prometheus
        target: /prometheus
    ports:
      - "9090:9090"
    networks:
      - prom

  grafana:
    depends_on:
      - prometheus
    image: grafana/grafana:latest
    hostname: grafana
    container_name: grafana
    volumes:
      - type: volume
        source: grafana
        target: /var/lib/grafana
    ports:
      - "3000:3000"
    networks:
      - prom

volumes:
  prometheus:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /opt/dmgeo/prom/prometheus/data
  grafana:
    driver: local
    driver_opts:
      type: none
      o: bind
      device: /opt/dmgeo/prom/grafana

networks:
  prom:
    driver: bridge

注:配置文件中device的目录可以自己选择,但是一定要提前创造好。

2.配置好yml文件之后直接docker-compose拉取就行了

docker-compose -f xxx.yml up -d