首页 > 解决方案 > Hazelcast 无法连接到 Hazelcast-mancenter

问题描述

我编写了以下 docker-compose.yml 来使用 Mancenter 构建一个正在运行的 Hazelcast Docker-Instance。

version: "3"
services:
    hazelcast:
        image: hazelcast/hazelcast:3.12.9
        container_name: hazelcast
        restart: unless-stopped
        environment:
            MAX_HEAP_SIZE: "512m"
            MIN_HEAP_SIZE: "512m"
            JAVA_OPTS: "-Dhazelcast.rest.enabled=true
                        -Dhazelcast.mancenter.enabled=true
                        -Dhazelcast.mancenter.url=http://localhost:8080/hazelcast-mancenter"
        ports:
            - "5701:5701"
        networks:
            - default

    hazelcast-management:
        image: hazelcast/management-center:3.12.9
        container_name: hazelcast-management
        restart: unless-stopped
        ports:
            - "8080:8080"
        networks:
            - default

networks:
  default:
    driver: bridge

日志总是显示以下错误,即使我使用“127.0.0.1”或我的 IP 而不是 localhost。我对两者都使用相同的版本:hc 和 hc-mancenter。

hazelcast               | Sep 23, 2020 11:38:35 AM com.hazelcast.internal.management.ManagementCenterService
hazelcast               | INFO: [192.168.160.3]:5701 [dev] [3.12.9] Failed to pull tasks from Management Center
hazelcast               | Sep 23, 2020 11:38:35 AM com.hazelcast.internal.management.ManagementCenterService
hazelcast               | INFO: [192.168.160.3]:5701 [dev] [3.12.9] Failed to connect to: http://localhost:8080/hazelcast-mancenter/collector.do

问候, 多姆

标签: dockerdocker-composehazelcast

解决方案


docker-compose 中的服务位于同一个“docker 网络”上,可以通过服务名称访问。当您使用 localhost 或 127.0.0.1 时,容器会尝试与其“自己的”localhost 进行通信。因此,Dhazelcast.mancenter.url=http://localhost:8080您应该连接到Dhazelcast.mancenter.url=http://hazelcast-management:8080. hazelcast 服务的容器应该有一个主机条目,将名称hazelcast-management指向正确的容器 ip。


推荐阅读