首页 > 解决方案 > 在 java docker 容器中重新绑定 RMI 端口

问题描述

我有一个在端口 3456 上运行 RMI 注册表的简单 Java 应用程序,它只是启动期间的一个注册表,它不公开任何服务。相反,我有一个客户端,它基本上获取注册表并动态绑定服务。但是我收到错误

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: 
    java.rmi.AccessException: Registry.bind disallowed; origin /172.17.0.1 is non-local host

下面是主类

public class RMIMock {

    public static void main(String... args) throws RemoteException {

        SpringApplication.run(RMIMock.class, args);

        LocateRegistry.createRegistry(3456); // this line of code automatic creates a new RMI-Registry. Existing one can be also reused.

    }
}

Dockerfile:

# we will use openjdk 8 with alpine as it is a very small linux distro
FROM container-registry.ubs.net/openjdk:8-jre-alpine3.8

# copy the packaged jar file into our docker image
COPY target/xcoll-virtualization-rmi-service-1.0-SNAPSHOT.jar /demo.jar

# set the startup command to execute the jar
CMD ["java", "-jar", "/demo.jar"]

运行图像的命令

docker run -p 3456:3456 -it xcoll-virtualization-rmi-service:1.0

客户:

LocateRegistry.getRegistry("localhost", 3456).bind("testDao", new RmiMockImpl());

        RMIDao rmiDao = (RMIDao) Naming.lookup("rmi://10.203.178.10:1200/testDao");
        System.out.println(rmiDao.getAllForDate(new Date()));

标签: javadockerrmi

解决方案


推荐阅读