【发布时间】:2019-07-12 19:41:21
【问题描述】:
我有一个基于微服务的节点应用程序。我正在使用 docker、docker-compose 和 traefik 进行服务发现。
此时我有 2 个微服务:
- 服务器应用:在 node-app.localhost:8000 运行
- 在 search-microservice.localhost:8002 运行的搜索微服务
我无法从一个微服务向另一个微服务发出请求的问题。 这是我的 docker compose 配置:
# all variables used in this file are defined in the .env file
version: "2.2"
services:
node-app-0:
container_name: node-app
restart: always
build: ./backend/server
links:
- ${DB_HOST}
depends_on:
- ${DB_HOST}
ports:
- "8000:3000"
labels:
- "traefik.port=80"
- "traefik.frontend.rule=Host:node-app.localhost"
reverse-proxy:
image: traefik # The official Traefik docker image
command: --api --docker # Enables the web UI and tells Traefik to listen to docker
ports:
- "80:80" # The HTTP port
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock
search-microservice:
container_name: ${CONTAINER_NAME_SEARCH}
restart: always
build: ./backend/search-service
links:
- ${DB_HOST}
depends_on:
- ${DB_HOST}
ports:
- "8002:3000"
labels:
- "traefik.port=80"
- "traefik.frontend.rule=Host:search-microservice.localhost"
volumes:
node-ts-app-volume:
external: true
node-app 和 search-microservice 都暴露了 3000 端口。
为什么我不能从节点应用程序调用http://search-microservice.localhost:8002?但是从浏览器调用它是可行的。
【问题讨论】:
标签: node.js docker docker-compose microservices traefik