我在单独的容器中提供以下服务,如您在docker-composer.yml文件中所看到的。我无法将一项服务链接到另一项服务。我正在尝试在网桥的gms-api-gateway中访问服务,该服务基于在端口7100上公开的节点构建。但是连接被拒绝了。
docker-compose.yml
version: '3'
services:
gms-api-gateway:
restart: always
links:
- gms-customers
networks:
- backend
build:
dockerfile: Dockerfile.dev
context: ./gms-api-gateway
depends_on:
- gms-customers
ports:
- 7000:7000
volumes:
- './gms-api-gateway:/opt/app'
environment:
# - NODE_ENV=localhost
- NODE_PORT=7000
- NODE_HOST=http://localhost
- GMS_CUSTOMERS_NODE_HOST=http://gms-customers:7100
gms-customers:
restart: always
networks:
- backend
build:
dockerfile: Dockerfile.dev
context: ./gms-customers
depends_on:
- customers-db
ports:
- 7100:7100
volumes:
- './gms-customers:/opt/app'
environment:
- NODE_ENV=localhost
- NODE_PORT=7100
- CUSTOMER_DB_URI=postgres://postgres:password@customers-db/customersdb
customers-db:
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=postgres
- POSTGRES_DB=customersdb
image: 'postgres:12'
ports:
- '0.0.0.0:5433:5432'
networks:
backend:
driver: 'bridge'
gms-api-gateway
import 'reflect-metadata';
import {ApolloServer} from 'apollo-server';
import {ApolloGateway} from '@apollo/gateway';
const port = process.env.NODE_PORT || 7000;
const gateway = new ApolloGateway({
serviceList: [
{
name: 'customers',
url: `${process.env.GMS_CUSTOMERS_NODE_HOST}/graphql`
}
],
// Experimental: Enabling this enables the query plan view in Playground.
__exposeQueryPlanExperimental: false
});
(async () => {
const {schema, executor} = await gateway.load();
const server = new ApolloServer({
schema,
executor
});
server.listen(port, (): void =>
console.log(
`API Gateway is now running on ${process.env.NODE_HOST}:${port}/graphql`
)
);
})();
现在,服务gms-api-gateway试图从另一个名为gms-customers的服务访问graphql模式。但是在日志中,我收到了
Encountered error when loading customers at http://gms-customers:7100/graphql: request to http://gms-customers:7100/graphql failed, reason: connect ECONNREFUSED 172.18.0.2:7100
两个服务都在同一网络上。在gms-api-gateway ping gms-customers
内部有效!有人遇到过同样的问题吗?