Docker : How to connect one container to another container via a network

Published

I have been researching docker with eureka, and I thought I understood how it works, but instead I have confused my self.

There is a container for the eureka server, and a container for the eureka client. The eureka client needs to be able to access the eureka server.
So what I did was find the IP address of the container which is this case is 172.20.0.2
so in my eureka client I have
defaultZone: http://172.20.0.2:8761/eureka/

I have connected both services to a network

"Containers": {
            "128e40236b9dc7e45cd046e34a0e2d5851a24c6da4d9510003615079c6c07a1e": {
                "Name": "bankhost",
                "EndpointID": "c5fa49a2d2d17232fa03b38835430e10eb5f40017d092b80aa624f1245bf6ec1",
                "MacAddress": "02:42:ac:14:00:03",
                "IPv4Address": "172.20.0.3/16",
                "IPv6Address": ""
            },
            "151bb21fbae965d782d0aca6fbae3cb7d24b19755bc1f01049a7e7579621e171": {
                "Name": "eurekahost",
                "EndpointID": "dd260aecffc3336b96ecfab3c7f3e36191a2672e67ca29390c359fb6b30feb2f",
                "MacAddress": "02:42:ac:14:00:02",
                "IPv4Address": "172.20.0.2/16",
                "IPv6Address": ""
            }
        },

When I run docker compose up for my client service, it runs but I its not register with Eureka

my application.yml for Eureka server

server:
  port=8761
spring:
  application: eureka-service

eureka:
  client:
    validateCertificates: false
    registerWithEureka: false
    fetchRegistry: false
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

my server docker-compose.yml

version: '3'

services:
  eureka-server:
    image:  eurekaservice
    hostname: eureka-server
    container_name: eurekahost
    ports:
      - "8761:8761"
networks:
  default:
    external: true
    name: opspec

my application.yml for Eureka client

server:
  port=8080
spring:
  application: name=user-service

eureka:
  client:
    validateCertificates: true
    registerWithEureka: true
    fetchRegistry: true
    healthcheck:
      enabled: true
    serviceUrl:
      defaultZone: http://172.20.0.2:8761/eureka/

Client docker-compose

version: '3'

services:
  bank-server:
    image:  bankservice
    hostname: bank-server
    container_name: bankhost
    ports:
      - "8083:8080"
networks:
  default:
    external: true
    name: opspec

Source: Docker Questions

Published
Categorised as docker, dockerfile, netflix-eureka Tagged , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq