I'm implementing two services (server and client) running on two different containers and trying to use gRPC to communicate between them.
If I deploy the server as a container and run the client not on a container, everything works just fine. But if I deploy the client on a different container I get Error #01: could not retrieve restaurant's list: rpc error: code = Unavailable desc = grpc: the connection is unavailable
error.
What steps am I missing to communicate two different containers using gRPC?
PS: I would like to try without Kubernetes for now.
SERVER
func Serve() {
log.Println("serving...")
port := ":50051"
lis, err := net.Listen("tcp", port)
if err != nil {
log.Fatalf("failed to listen on port %s: %v", port, err)
}
s := grpc.NewServer()
server := server{}
RegisterNeo4BaconServer(s, server)
if err := s.Serve(lis); err != nil {
log.Fatal("could not serve: ", err)
}
}
Makefile
image: ## build docker image and push image to registry
@docker build -t neo4bacon -f resources/prod/Dockerfile .
run: ## deploy application container
@docker run --rm -d --name neo4bacon neo4bacon
CLIENT
func Get() (*api.RestaurantList, error) {
// Neo4bacon backend
backendPort := ":50051"
conn, err := grpc.Dial(backendPort, grpc.WithInsecure())
if err != nil {
&api.RestaurantList{}, fmt.Errorf("could not connect to backend %s: %s", backendPort, err)
}
defer conn.Close()
client := api.NewNeo4BaconClient(conn)
restaurantList, err := client.List(context.Background(), &api.Empty{})
if err != nil {
return &api.RestaurantList{}, fmt.Errorf("could not retrieve restaurant's list: %s", err)
}
return restaurantList, nil
}
Makefile
image: ## build docker image and push image to registry
@docker build -t alesr/bacon-api -f resources/prod/Dockerfile .
run: ## deploy docker container
@docker run --rm -d -p 8080:8080 --name bacon-api bacon-api