-1

I have 2 Spring Boot micro-service applications i.e web application and metastore application. This is the properties file for my web application.

spring:
  thymeleaf:
    prefix: classpath:/static/
  application:
    name: web-server
  profiles:
     active: native

server:
  port: ${port:8383}

---
host:
  metadata: http://10.**.**.***:5011

Dockerfile for web application:

FROM java:8-jre
MAINTAINER **** <******>
ADD ./ms.console.ivu-ivu.1.0.1.jar /app/
CMD chmod +x /app/*
CMD ["java","-jar", "/app/ms.console.web-web.1.0.1.jar"]
EXPOSE 8383

Dockerfile for metadata application:

FROM java:8-jre
MAINTAINER ******* <********>
ADD config/* /deploy/config/
CMD chmod +x ./deploy/config/*
COPY ./ms.metastore.1.0.1.jar /deploy/
CMD chmod +x ./deploy/ms.metastore.1.0.1.jar
CMD ["java","-jar","./deploy/ms.metastore.1.0.1.jar"]
EXPOSE 5011

I am using Mesos and Marathon for cluster management. The Marathon scripts for metastore is :-

{
  "id": "/ms-metastore",
  "cmd": null,
  "cpus": 1,
  "mem": 2000,
  "disk": 0,
  "instances": 0,
  "acceptedResourceRoles": [
    "*"
  ],
  "container": {
    "type": "DOCKER",
    "docker": {
      "forcePullImage": true,
      "image": "*****/****:ms-metastore",
      "parameters": [],
      "privileged": true
    },
    "volumes": [],
    "portMappings": [
      {
        "containerPort": 5011,
        "hostPort": 0,
        "labels": {},
        "protocol": "tcp",
        "servicePort": 10000
      }
    ]
  },
  "networks": [
    {
      "mode": "container/bridge"
    }
  ],
  "portDefinitions": [],
  "fetch": [
    {
      "uri": "file:///etc/docker.tar.gz",
      "extract": true,
      "executable": false,
      "cache": false
    }
  ]
}

Web marathon:

{
  "id": "/ms-console",
  "cmd": null,
  "cpus": 1,
  "mem": 2000,
  "disk": 0,
  "instances": 0,
  "acceptedResourceRoles": [
    "*"
  ],
  "container": {
    "type": "DOCKER",
    "docker": {
      "forcePullImage": true,
      "image": "****/****:ms-console",
      "parameters": [],
      "privileged": true
    },
    "volumes": [],
    "portMappings": [
      {
        "containerPort": 8383,
        "hostPort": 0,
        "labels": {},
        "protocol": "tcp",
        "servicePort": 10000
      }
    ]
  },
  "networks": [
    {
      "mode": "container/bridge"
    }
  ],
  "portDefinitions": [],
  "fetch": [
    {
      "uri": "file:///etc/docker.tar.gz",
      "extract": true,
      "executable": false,
      "cache": false
    }
  ]
}

Web application I am connecting to metastore with IP which is hard coded (mentioned in properties). I created docker images for both and run in my server. The metastore server now running in different machine, so my web application is unable to resolve this IP.

halfer
  • 19,824
  • 17
  • 99
  • 186
Chintamani
  • 1,076
  • 7
  • 23
  • 47

1 Answers1

0

All you need to do here is expose 5011 as the host port on the metadata server running on "different machine" using -p -

docker run -d -p 5011:5011 metadata_image ....

Now your web application should be able to access metadata server by using http://$different_machine_ip:5011/

$different_machine_ip = Metadata server IP

However since they need to be tightly coupled, i would suggest you run web app & metadata server on the same machine in case your metadata server is stateless.

vivekyad4v
  • 13,321
  • 4
  • 55
  • 63
  • 1
    I would not rely in IP addresses. Docker networking provides aliases for hosts through it own internal web Server. Either use those directly or use environment variables in the properties file – Marged Jan 22 '18 at 07:44
  • In that case you might want to use Swarm, KeyValue store & overlay network. Your current setup is prone to change, your question didn't specify that you want to use a DNS name. – vivekyad4v Jan 22 '18 at 08:19
  • Could me pls share me how I can use docker networking here – Chintamani Jan 22 '18 at 08:20
  • Ref - https://luppeng.wordpress.com/2016/05/03/setting-up-an-overlay-network-on-docker-without-swarm/ , this might help! – vivekyad4v Jan 22 '18 at 08:21