Search code examples
dockerdocker-composetraefikmoleculer

Moleculer metrics port not exposed in docker container


I'm using molecule for microservices. Actually I don't know how to expose the metrics port (3030) in the docker container to be able to read metrics from http://host:3030/metrics

when the app is executed ion my localhost it is working just fine but when deploying with docker-compose --build -up it don't work.

my docker compose traefik section

  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

Thank you for your help

The all 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:

Update: When running npm run dev on my local machine I can access metrics url at http://localhost:3030/metrics to get metrics for all running microservices. But when I deploy the code to the container (docker-compose.yml above) the application run perfectly on http://host:3000 but http://localhost:3030/ is not accessible. I disabled the firewall but no luck I added port mapping 3030:3030 on traefik section on the docker-compose.yml file but nothing

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

Thank you for your help and your patience


Solution

  • Finally got it In docker-compose.yml on the api service declaration just added ports: 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
    

    Thank you