0

我正在将分子用于微服务。实际上我不知道如何在 docker 容器中公开指标端口(3030)以便能够从 http://host:3030/metrics 读取指标

当应用程序在我的本地主机上执行时,它工作得很好,但是在使用 docker-compose --build -up 部署时它不起作用。

我的 docker 撰写 traefik 部分

  traefik:
    image: traefik:v2.1
    command:
      - "--api.insecure=true" # Don't do that in production!
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
    ports:
      - 3000:80
      - 3001:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - internal
      - default

谢谢您的帮助

所有 docker-compose.yml

version: "3.3"

services:
  api:
    build:
      context: .
    image: moleculer-akwa
    env_file: docker-compose.env
    environment:
      SERVICES: api
      PORT: 3000
    depends_on:
      - nats
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
      - "traefik.http.services.api-gw.loadbalancer.server.port=3000"
    networks:
      - internal
        
  firebase:
    build:
      context: .
    image: moleculer-akwa
    env_file: docker-compose.env
    environment:
      SERVICES: firebase
    depends_on:
      - nats
    networks:
      - internal
        
  kafka:
    build:
      context: .
    image: moleculer-akwa
    env_file: docker-compose.env
    environment:
      SERVICES: kafka
    depends_on:
      - nats
    networks:
      - internal

  mailer:
    build:
      context: .
    image: moleculer-akwa
    env_file: docker-compose.env
    environment:
      SERVICES: mailer
    depends_on:
      - nats
    networks:
      - internal

  sms:
    build:
      context: .
    image: moleculer-akwa
    env_file: docker-compose.env
    environment:
      SERVICES: sms
    depends_on:
      - nats
    networks:
      - internal
        
  
  io:
    build:
      context: .
    image: moleculer-akwa
    env_file: docker-compose.env
    environment:
      SERVICES: io
      PORT: 5000
    depends_on:
      - nats
    networks:
      - internal

  nats:
    image: nats:2
    networks:
      - internal

  traefik:
    image: traefik:v2.1
    command:
      - "--api.insecure=true" # Don't do that in production!
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
    ports:
      - 3000:80
      - 3001:8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - internal
      - default

networks:
  internal:

volumes:
  data:

更新:npm run dev在我的本地机器上运行时,我可以在 http://localhost:3030/metrics 访问指标 url,以获取所有正在运行的微服务的指标。但是当我将代码部署到容器(上面的 docker-compose.yml)时,应用程序在 http://host:3000 上完美运行,但 http://localhost:3030/ 无法访问。我禁用了防火墙但没有运气我在 docker-compose.yml 文件的 traefik 部分添加了端口映射 3030:3030 但没有

ports:
          - 3000:80
          - 3001:8080
          - 3030:3030

感谢您的帮助和耐心

4

2 回答 2

1

您是否使用 Prometheus 作为导出器?如果是这种情况,请检查https://github.com/AndreMaz/moleculer-prometheus-demo

于 2021-03-11T16:00:13.863 回答
0

终于搞定了在docker-compose.yml上的api服务声明中刚刚添加了端口:3030:3030

api:
build:
  context: .
environment:
  SERVICES: api
  PORT: 3000
depends_on:
  - nats
ports:
  - 3030:3030
labels:
  - "traefik.enable=true"
  - "traefik.http.routers.api-gw.rule=PathPrefix(`/`)"
  - "traefik.http.services.api-gw.loadbalancer.server.port=3000"
networks:
  - internal

谢谢

于 2021-03-19T08:01:33.557 回答