Nestcloud 로커-을 구성하사 마이크로 서비스를 연결이 거부

0

질문

나 dockerize 을 a nestcloud 앱으로 영사 무리의 마이크로 서비스. 그러나 나는 할 수 없을 시작하 microservice(예:테스트 서비스는 아래의 것 영사에게 어떤 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

여기에 내 docker-compose.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"

가능한 microservice 테스트 서비스:

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"]

과 부트스트랩 있습니다.yaml 사용 nestcloud 을 실행하 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

나는 성공적으로 ping 영사관에서 컨테이너 microservice 컨테이너:

docker exec -ti test-service ping consul

당신은 아무것도 잘못된 내 config,그렇다면 당신에게 말할 수 있는 방법을까요?

1

최고의 응답

0

당신은에 액세스하려는 영사와 함께 localhost 에서 NestJs 서비스,이것은 다른 컨테이너,그것은 로컬 호스트에서 다른 영사 localhost,당신은에 액세스해야 consule 컨테이너 이름으로 호스트

변경사의 호스트 ${{ CONSUL_HOST }}bootstrap-development.yaml.

CONSUL_HOST 에서 정의 docker-compose.yaml: CONSUL_HOST=consul

bootstrap-development.yaml:

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

하고 다시 작성 컨테이너: docker-compose --project-directory=. -f docker-compose.dev.yml up --build

2021-12-05 18:06:28

Yup,그것처럼 보인다. 감사합니다!
Bruno Paris

는 경우 그것은 당신을 도움을 받아주십시오 클릭하여 답 V
Raz Luvaton

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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