我的本地(没有 docker)很好,工作没有任何问题。
本地设置工作正常。
Server-Jar:运行于 8081
Client-War:运行在 8000,可以毫无问题地连接到 Server Jar。
DOCKER 设置docker-compose.yml
服务器
employee:
image: openjdk:jdk-alpine
container_name: "employee"
ports:
- 9081:8080
- 9991:9990
- 65193:65193
volumes:
- ./Employee/target/Employee-1.0-SNAPSHOT-jar-with-dependencies.jar:/deployments/Employee-1.0-SNAPSHOT-jar-with-dependencies.jar
environment:
- JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=0.0.0.0:65193,suspend=n,server=y -Djava.net.preferIPv4Stack=true
- GRPC_PORT=8080
command: java -jar /deployments/Employee-1.0-SNAPSHOT-jar-with-dependencies.jar
client:
image: jboss/wildfly
container_name: "client"
ports:
- 9080:8080
- 9990:9990
- 65193:65193
volumes:
- ./Service/target/Service.war:/opt/jboss/wildfly/standalone/deployments/Service.war
environment:
- JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=0.0.0.0:65193,suspend=n,server=y -Djava.net.preferIPv4Stack=true
- EMPLOYEE_HOST=localhost:9081
command: >
bash -c "/opt/jboss/wildfly/bin/add-user.sh admin Admin#007 --silent && /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0"
links:
- employee
depends_on:
- employee
员工服务器代码
Server server = ServerBuilder.forPort(Integer.parseInt(env.get("GRPC_PORT")))
.addService(new Employee())
.build();
try {
server.start();
System.out.println("Server listening at: " + env.get("GRPC_PORT"));
server.awaitTermination();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
客户端连接代码。
ManagedChannel channel = ManagedChannelBuilder.forTarget(env.get("EMPLOYEE_HOST")).usePlaintext().build();
EmployeeServiceGrpc.EmployeeServiceBlockingStub employee = EmployeeServiceGrpc.newBlockingStub(channel);
当我进行 gRPC 调用时抛出错误。
您认为 docker 设置正确吗?如果那么我可以在其他地方寻找问题
Qyouu
相关分类