I have a few simple REST api services implemented in Express.These services run in docker containers in a swarm mode.Also,I am trying to use express-api gateway with these services.The express api gateway also runs in a container as part of the docker swarm.Following is the Dockercompose file
version: "3"
services:
firstService:
image: chaitanyaw/firstrepository:first
deploy:
replicas: 3
restart_policy:
condition: on-failure
ports:
- '3000:3000'
networks:
- webnet
apiGateway:
image: firstgateway:latest
deploy:
restart_policy:
condition: on-failure
ports:
- '80:80'
networks:
- webnet
visualizer:
image: dockersamples/visualizer:latest
ports:
- 8080:8080
volumes:
- /var/run/docker.sock:/var/run/docker.sock
deploy:
placement:
constraints: [node.role == manager]
networks:
- webnet
networks:
webnet:
also, following is the gateway.config file
http:
port: 80
admin:
port: 9876
hostname: localhost
apiEndpoints:
api:
host: 192.168.99.100
paths: '/ip'
localApi:
host: 192.168.99.100
paths: '/'
serviceEndpoints:
httpbin:
url: 'https://httpbin.org'
services:
urls:
- 'http://192.168.99.100:3000/serviceonerequest'
- 'http://192.168.99.100:3000/servicetwo'
policies:
- basic-auth
- cors
- expression
- key-auth
- log
- oauth2
- proxy
- rate-limit
pipelines:
default:
apiEndpoints:
- api
policies:
# Uncomment `key-auth:` when instructed to in the Getting Started guide.
# - key-auth:
- proxy:
- action:
serviceEndpoint: httpbin
changeOrigin: true
customPipeline:
apiEndpoints:
- localApi
policies:
- proxy:
- action:
serviceEndpoint: services
changeOrigin: true
The ip '192.168.99.100' is the docker-machine ip. If I run the stack using the above gateway.config file, everything works fine. However,IF I replace
services:
urls:
- 'http://192.168.99.100:3000/serviceonerequest'
- 'http://192.168.99.100:3000/servicetwo'
with
services:
urls:
- 'http://services_firstService:3000/serviceonerequest'
- 'http://services_firstService:3000/servicetwo'
I get a bad gateway! This docker swarm runs an overlay network "webnet".So,I must be able to use the service name as the hostname in the gateway.config file according to this link. In the above working case with the use of IP the services become available 'outside' of the gateway which I do not desire. What is wrong?