Nestcloud con mobile-comporre console micro-servizio di connessione rifiutata

0

Domanda

Ho dockerize un nestcloud app con il console e un mazzo di microservices. Tuttavia, io sono in grado di avviare qualsiasi microservice (per esempio test-servizio qui di seguito, come sembra console rifiuta qualsiasi connessione tcp :

[Nest] 1   - 11/23/2021, 9:47:34 PM   [NestFactory] Starting Nest application... 
[Nest] 1   - 11/23/2021, 9:50:56 PM   [ConfigModule] Unable to initial ConfigModule, retrying...
[Nest] 1   - 11/23/2021, 9:47:34 PM   [InstanceLoader] ServiceRegistryModule dependencies initialized +114ms
[Nest] 1   - 11/23/2021, 9:47:34 PM   [InstanceLoader] LoggerModule dependencies initialized +0ms
[Nest] 1   - 11/23/2021, 9:47:34 PM   [InstanceLoader] BootModule dependencies initialized +0ms
[Nest] 1   - 11/23/2021, 9:47:34 PM   [InstanceLoader] HttpModule dependencies initialized +6ms
[Nest] 1   - 11/23/2021, 9:47:34 PM   [InstanceLoader] AppModule dependencies initialized +2ms
[Nest] 1   - 11/23/2021, 9:47:34 PM   [InstanceLoader] ConsulModule dependencies initialized +0ms
[Nest] 1   - 11/23/2021, 9:47:34 PM   [ConfigModule] Unable to initial ConfigModule, retrying... +39ms
Error: consul: kv.get: connect ECONNREFUSED 127.0.0.1:8500

Ecco la mia finestra mobile-comporre.yaml :

version: "3.2"

services:
  test-service:
    build:
      context: .
      dockerfile: apps/test-service/Dockerfile
      args:
        NODE_ENV: development
    image: "test-service:latest"
    restart: always
    depends_on:
      - consul
    environment:
      - CONSUL_HOST=consul
      - DISCOVERY_HOST=localhost
    ports:
      - 50054:50054

  consul:
    container_name: consul
    ports:
      - "8400:8400"
      - "8500:8500"
      - "8600:53/udp"
    image: consul
    command: ["agent", "-server", "-bootstrap", "-ui", "-client", "0.0.0.0"]
    labels:
      kompose.service.type: nodeport
      kompose.service.expose: "true"
      kompose.image-pull-policy: "Always"

il Dockerfile per il mio microservice test-servizio di :

FROM node:12-alpine
ARG NODE_ENV=production
ENV NODE_ENV $NODE_ENV

RUN mkdir -p /usr/src/app
ADD . /usr/src/app

WORKDIR /usr/src/app

RUN yarn global add @nestjs/cli

RUN yarn install --production=false

# Build production files
RUN nest build test-service

# Bundle app source
COPY . .

EXPOSE 50054
CMD ["node", "dist/apps/test-service/main.js"]

e il bootstrap-sviluppo.yaml utilizzato da nestcloud per lanciare il microservice

consul:
  host: localhost
  port: 8500
config:
  key: mybackend/config/${{ service.name }}
service:
  discoveryHost: localhost
  healthCheck:
    timeout: 1s
    interval: 10s
    tcp: ${{ service.discoveryHost }}:${{ service.port }}
  maxRetry: 5
  retryInterval: 5000
  tags: ["v1.0.0", "microservice"]
  name: io.mybackend.test.service
  port: 50054
loadbalance:
  ruleCls: RandomRule
logger:
  level: info
  transports:
    - transport: console
      level: debug
      colorize: true
      datePattern: YYYY-MM-DD h:mm:ss
      label: ${{ service.name }}
    - transport: file
      name: info
      filename: info.log
      datePattern: YYYY-MM-DD h:mm:ss
      label: ${{ service.name }}
      # 100M
      maxSize: 104857600
      json: false
      maxFiles: 10
    - transport: dailyRotateFile
      filename: info.log
      datePattern: YYYY-MM-DD-HH
      zippedArchive: true
      maxSize: 20m
      maxFiles: 14d

Posso eseguire il ping il console contenitore dal microservice contenitore con :

docker exec -ti test-service ping consul

Non si vede niente di sbagliato con la mia config, e se è così potete dire come posso farlo funzionare per favore ?

1

Migliore risposta

0

Cercando di accedere al console con localhost da NestJs servizio, questo è un altro contenitore, è localhost è diverso da console localhost, è necessario accedere consule con il nome del contenitore come host

Cambiare console host ${{ CONSUL_HOST }} in bootstrap-development.yaml.

CONSUL_HOST è definito in docker-compose.yaml: CONSUL_HOST=consul

nuovo bootstrap-development.yaml:

consul:
  host: ${{CONSUL_HOST}}
  port: 8500
...

e ricostruito il contenitore con : docker-compose --project-directory=. -f docker-compose.dev.yml up --build

2021-12-05 18:06:28

Yup, sembra di sì. Grazie!
Bruno Paris

Se ti ha aiutato, si prega di accettare la risposta, cliccando il V
Raz Luvaton

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................