Docker communication between two containers with Java

前端 未结 2 1898
时光说笑
时光说笑 2021-01-07 03:39

There are two java files, Server.java and Client.java. Both are in separate containers.

DOCKER FILES: The dockerfile(in the folder named \'Server\')

2条回答
  •  走了就别回头了
    2021-01-07 04:08

    There are 3 problems:

    1. The classes should be named Server and Client, or else the Server.java & Client.Java files should be named MyServer.java & MyClient.java, respectively.
    2. When you create a Docker container, 2 interfaces are created: localhost and another interface for communicating with other containers. You should change "localhost" to the server container IP or the host IP.
    3. The java images are deprecated.

    Also, there's no need for the EXPOSE directive in the client Dockerfile.

提交回复
热议问题