java - 在 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()));
解决方案
推荐阅读
- hive - Hive 查询计划中的“宽度”是什么意思?
- javascript - 产生适合作为 Javascript 标识符的清晰编码的文本编码?
- docker - 通过 Oracle VM 和 cntlm 代理从 docker 内部访问 Internet
- mysql - 选择语句的选择案例结果(检查多行的条件)
- php - PHP JSON 编码不带 []
- javascript - 单选按钮未选择
- visual-studio - 如何正确更新 Visual Studio 源文件/目录
- python - 在 ODE 中使用事件的时间
- javascript - CSS, HTML 列表缩进
- twilio - 使用 Twilio 进行双通道录制?