0

I've got a simple webapp that has a web-server and a restful api-service. I cannot get the web-server app to connect to the restful api-service using the service name. I can reach the api service if I use the IP address.

Here's my compose file

version: '3'

services:

  my-app:
    image: my-app:1.0.0
    ports: 
      - "5000:5000"
    networks:
      - my-network

  my-api:
    image: my-api:1.0.0
    ports: 
      - "3000:3000"
    networks:
      - my-network

networks:
  my-network:

I'm running a swarm on a single machine with 1 replica. If I connect with the local IP address in the web-app it connects but fails when I try http://my-api:3000

Any ideas?

  • Your localhost doesn't have a DNS to know what `my-api` represents, or are you trying to connect between services? – OneCricketeer Jun 25 '18 at 02:14
  • Yes, this is connecting two services, my-app and my-api I know I won't be able to reach from the host but I expected anything inside the swarm would be able to reach other containers by service name? – David Broadhurst Jun 25 '18 at 02:23
  • It should, yes. I've not used Swarm myself, however. My suggestion would be to attach to one container and run commands such as nslookup and traceroute to diagnose networking problems – OneCricketeer Jun 25 '18 at 10:51

1 Answers1

0

I found I could ping the api from the app using the dns name. The issue was even though the app is in the swarm the app is running outside the swarm