0

I'm a very beginner in docker world, and I'm not able to make two containers communicate using docker compose. I have two containers:

  • Service Registry: a simple spring boot application using Netflix Eureka to implement a service registry feature.
  • API Gateway: a simple spring boot application using Netflix Zuul. This application will try periodically to be registered into the Service Registry application by connecting to a given URL

All work fine without docker !! And now with docker-compose, the gateway is not able to find the Eureka server URL.

docker-compose.yml file:

version: '3.5'
services:

gateway:
 build:
  context: ../robots-store-gateway
  dockerfile: Dockerfile
 image: robots-store-gateway
 ports:
  - 8000:8000
 networks:
  - robots-net

serviceregistry:
 build:
  context: ../robots-sotre-serviceregistry
 image: robots-sotre-serviceregistry
 ports:
  - 8761:8761
 networks:
  - robots-net

networks:
 robots-net:
  name: custom_network
  driver: bridge

The application.yml file of the gateway is:

eureka:
  client:
    service-url:
      default-zone: http://serviceregistry:8761/eureka/

I receive this exception:

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)

I tried different ways to configure the Eureka client but no way !! it doesn't work. Thanks in advance.

Hedi Ayed
  • 371
  • 2
  • 3
  • 12
  • Hi, Why did you add a network? Is it necessary? Try the docker compose magic, and remove all the network parts. You should be able to use the same url (http://serviceregistry:8761/eureka/). And I also think you don't need to expose the services to other services or containers, so you can remove the "ports" parts too. – Fiber Optic Mar 22 '18 at 00:12
  • What's in the logs for the serviceregistry process when it starts up? Can you curl the url from your machine? Can you curl the url from the `serviceregistry` container? – Matt Mar 22 '18 at 06:09
  • I'm not able to curl the `serviceregistry` container from neither the `apigateway`container nor from the host. The problem is that the containers are using a hostname as the container id even when I explicitly give a name with `--name` – Hedi Ayed Mar 22 '18 at 20:54

2 Answers2

0

I don't exactly why !!! But finally, this works for me:

version: '3.5'
services:

 gateway:
   container_name: gateway
   build:
    context: ../robots-store-gateway
    dockerfile: Dockerfile
   image: robots-store-gateway
   ports:
    - 8000:8000
   hostname: gateway
   environment:
     eureka.client.serviceUrl.defaultZone: http://serviceregistry:8761/eureka/

 serviceregistry:
   container_name: serviceregistry
   build:
    context: ../robots-sotre-serviceregistry
   image: robots-sotre-serviceregistry
   ports:
    - 8761:8761
   hostname: serviceregistry
   environment:
    eureka.client.serviceUrl.defaultZone: http://serviceregistry:8761/eureka/
Hedi Ayed
  • 371
  • 2
  • 3
  • 12
-1

You didn't set the container name. Link

And the url or ip should replace to container name.

Example: mongodb://{container_name}:27017

Rukeith
  • 665
  • 1
  • 8
  • 22