kotlin - Apollo Federation 无法在 docker-compose 中运行连接:无法加载服务定义...原因:连接 ECONNREFUSED 127.0.0.1:80
问题描述
我试图通过 docker-compose 运行两个应用程序但没有成功,联邦无法连接服务。两者都可以在 docker 中很好地工作。
下面关注项目:
NodeJS 中的 Apollo 服务器联合
Kotlin + Spring Boot + expediagroup 中的 GraphQL API:graphql-kotlin-spring-server
码头工人-compose.yml
version: '3'
services:
myservice:
image: 'myservice:0.0.1-SNAPSHOT'
container_name: myservice_container
ports:
- 8080:8080
expose:
- 8080
apollo_federation:
image: 'apollo-federation'
build: '.'
container_name: apollo_federation_container
restart: always
ports:
- 4000:4000
expose:
- 4000
environment:
ENDPOINT: "http://myservice/graphql"
depends_on:
- myservice
我已经在端点 ex 中尝试了很多组合:http://myservice:8080/graphql、http://localhost:8080/graphql、http://myservice 等...
来自 Apollo 项目的 index.js
const { ApolloServer } = require("apollo-server");
const { ApolloGateway } = require("@apollo/gateway");
const gateway = new ApolloGateway({
serviceList: [
{ name: "Service1", url: process.env.ENDPOINT || 'http://localhost:8080/graphql' },
]
});
const server = new ApolloServer({
gateway,
subscriptions: false
});
server.listen().then(({ url }) => {
console.log(` Server ready at ${url}`);
})
错误日志
Error checking for changes to service definitions: Couldn't load service definitions for "Service1" at http://myservice/graphql: request to http://myservice/graphql failed, reason: connect ECONNREFUSED 172.18.0.3:80
如果我尝试从浏览中进行测试,我会得到 graphiql 的错误 500。
我已经尝试使用 nginx 作为反向代理,但没有成功
我正在使用项目中的最后一个库。
谢谢
解决方案
在您的代码中,您正在使用
{ name: "Service1", url: process.env.ENDPOINT || 'http://localhost:8080/graphql' },
这是 pull process.env.ENDPOINT
,它在您的 docker-compose 文件中定义为使用端口 80:
environment:
ENDPOINT: "http://myservice/graphql" # This is port 80
推荐阅读
- gcc - 在 NASM 和 GCC 中提供 incbin 路径作为预定义的宏
- c++ - 如何检查排序算法的空间复杂度?
- python - 如何循环遍历字典以更新并返回它?
- html - 在 html 中使用字体
- amazon-web-services - 是否可以在 cognito 中添加静态用户?
- javascript - 如何为谷歌地图标记设置新坐标?
- kotlin - kotlin协程withTimeout在使用withContext获取非阻塞代码时不取消
- swift - 单击 Google 登录按钮时没有任何反应
- javascript - Lodash - 搜索字符串是否包含以开头的单词
- angular - Angular:使用 HttpClient、Observable 和异步管道加载 http 数据时的工作