问题
I have following services in separate containers as you can see in the docker-composer.yml file. I'm unable to link one service to another. I'm trying to access service, built on node exposing on port 7100, in gms-api-gateway on network bridge. But connection is being refused.
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`
)
);
})();
Now, the service gms-api-gateway is trying to access graphql schema from another service called gms-customers. But in logs I'm receiving this
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
Both services are at the same network. Inside gms-api-gateway ping gms-customers
works! Someone faced the same issue?
来源:https://stackoverflow.com/questions/60534429/access-docker-container-from-another-docker-container