Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
Java RMI in docker

I've been trying to get a Java RMI application to work in docker as a test for some time now.

The application works when both components are on the same PC, when the "server" is in docker not.

How can I execute a remote method that I've dockerized?

There is a snippet of my Client:

Registry registry = LocateRegistry.getRegistry(DOCKER_EXPOSED_PORT);

     // this prints any found registry names
     String[] s = registry.list();
     System.out.println(s[0]);

     CommonInterface stub = (CommonInterface) registry.lookup("RegisteredStub");
     int response = stub.CommonMethod();

And my "server":

CommonInterface stub = (CommonInterface) UnicastRemoteObject.exportObject(obj, 2000);

  LocateRegistry.createRegistry(2000);
  Registry registry = LocateRegistry.getRegistry(2000);
  registry.bind("RegisteredStub", stub);

I also use System.out.println(Inet4Address.getLocalHost().getHostAddress()); to get the IP address of both components, they are the same when ran locally but diffrent when the server is in docker as expected.

My client is able to "read" the registered stub from the docker container so if I rename it to RegisteredStub2 then

String[] s = registry.list();
System.out.println(s[0]);

prints RegisteredStub2 so somehow my client can see the registry in docker but can not access the remote method.

The client crashes with: java.net.ConnectException: Connection timed out: connect java.rmi.ConnectException: Connection refused to host: DOCKER IP;

when I call the remote method int response = stub.CommonMethod(); from the desktop client.

Here are my docker file commands:

EXPOSE 2000
CMD ["./rmiregistry 2000"]
CMD ["./rmid -J-Djava.security.policy=rmid.policy -port 2000"]

Thanks!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Might be too late to be of any use, but I just recently built a multi-module maven project for a college assignment and dockerized it.

Your docker-compose.yml should look something like this:

version: '3'
services:
    server:
      build: server
    client:
      build: client
      environment: 
          SERVER_HOST: server
      depends_on:
      - server

Your servers Dockerfile something like this:

FROM openjdk:8-jre-alpine
COPY target/server-jar-with-dependencies.jar /server.jar
CMD /usr/bin/java -jar /server.jar

And your clients Dockerfile something like this:

FROM openjdk:8-jre-alpine
ENV SERVER_HOST=localhost
COPY target/client-jar-with-dependencies.jar /client.jar
CMD /usr/bin/java -jar /client.jar $SERVER_HOST

Note the $SERVER_HOST variable passed to the client, this will allow you to do the following in the client code:

Registry registry = LocateRegistry.getRegistry(args[0]);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda