docker将如何解析属性文件中的主机名或ip?

nwwlzxa7  于 2021-06-26  发布在  Mesos
关注(0)|答案(1)|浏览(362)

我有两个springboot微服务应用程序,即web应用程序和metastore应用程序。这是我的web应用程序的属性文件。

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

server:
  port: ${port:8383}

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

web应用程序的dockerfile:

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:

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

我使用mesos和marathon进行集群管理。metastore的marathon脚本是:-

{
  "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
    }
  ]
}

网络马拉松:

{
  "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
    }
  ]
}

我正在用硬编码的ip连接到metastore的web应用程序(在属性中提到)。我为两者创建了docker映像,并在我的服务器中运行。metastore服务器现在运行在不同的计算机上,因此我的web应用程序无法解析此ip。

ztigrdn8

ztigrdn81#

你要做的就是暴露 5011 作为在“不同的机器”上运行的元数据服务器上的主机端口,使用 -p - docker run -d -p 5011:5011 metadata_image .... 现在,您的web应用程序应该能够使用 http://$different_machine_ip:5011/ $different\u machine\u ip=元数据服务器ip
但是,由于它们需要紧密耦合,我建议您在同一台机器上运行web应用程序和元数据服务器,以防元数据服务器是无状态的。

相关问题