我试图在Docker映像中包含基于gRPC的系统,最终目标是在基于kubernetes的部署中使用。当将服务器和客户端作为独立文件运行时,一切都正常工作。服务器的主要功能如下:
func main() {
//Start listening to tcp port, if cannot connect then throw an error
const (
port = ":50051"
)
listen, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
//start the new server with grpc
s := grpc.NewServer()
VEIv1_0.RegisterVEIv1_0Server(s, &server{})
// Connnect to cloud service procviders
iotCore = connectToAWSIoT()
log.Println("Connected to AWS")
//mqttCli, topic = connectToGCPIoT()
//log.Println("Connected to GCP")
if err := s.Serve(listen); err != nil {
log.Fatalf("failed to serve: %v", err)
}}
在将其转换为图像后,我将使用docker run -d -rm --name windows-server -p 50051:50051 windows-server启动容器。根据日志,它正在按预期运行。当我尝试用不同的程序连接到容器时,使用
def main():
frameNum = 0
host = '172.17.0.4'
#According to docker container inspect, this is the IP of the Container
server_port = 50051
#instantiate a channel
channel = grpc.insecure_channel(
'{}:{}'.format(host, server_port)
)我收到以下错误
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:172.17.0.4:50051: tcp handshaker shutdown"
debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNKNOWN: ipv4:172.17.0.4:50051: tcp handshaker shutdown {grpc_status:14, created_time:"}"我也尝试使用网关IP地址和DNS,也有错误。我做错了什么?
发布于 2022-11-11 19:08:28
问题的根源在于服务器程序中有另一个错误,导致它以错误终止。当发生这种情况时,容器就会停止。客户端无法连接到服务器容器,因为服务器容器已经停止。
https://stackoverflow.com/questions/74382040
复制相似问题