我正在将分子用于微服务。实际上我不知道如何在 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
感谢您的帮助和耐心