C
C#13mo ago
Denis

✅ How to deploy gRPC Server + Client via docker

I wish to have a gRPC server and multiple clients connected to said server. In my current setup, I have two Blazor-server clients and a bare-bones console app client. Only the console app is currently configured as a receiving client. The goals are: 1. Communicate with the server from my local env. to the running docker instance. 2. Enable the aforementioned applications to communicate with each other. Unfortunately, I'm having issues with both goals. At some point, I was able to send requests to the server (goal 1); however, the apps still refused to connect (goal 2). I've started from scratch and uploaded the project online for you to have a closer look: https://github.com/hailstorm75/GrpcDocker-Experiment For goal 1 I have tried various combinations of exposing ports in the docker-compose, Dockerfile, even dabbled in configuring servers appsettings.json and launchSettings.json. However, all of my attempts are just throwing things at the wall and seeing what sticks, without really understanding where I need to configure the ports. Running locally, I'm able to access the server and send a request. Running via docker, I see the exposed ports, however, I'm unable to send a request. Opening the port links shown in the image gives me an empty response in the browser, instead of the mapped "Communication with gRPC endpoints must be made through..." message. I'm testing the communication with the server via Postman. I've tried various ports, combined with enabled and disabled TLS just to be sure. With goal 2 I'm simply getting a SocketException:
Status(StatusCode="Unavailable", Detail="Error connecting to subchannel.", DebugException="System.Net.Sockets.SocketException: Cannot assign requested address")
Status(StatusCode="Unavailable", Detail="Error connecting to subchannel.", DebugException="System.Net.Sockets.SocketException: Cannot assign requested address")
16 Replies
Denis
Denis13mo ago
I'm getting this exception in the ConsoleListener when attempting to iterate the ResponseStream:
const string MY_ID = "ConsoleListener";

using var channel = GrpcChannel.ForAddress("https://localhost:7261/");
var client = new Greeter.GreeterClient(channel);

var subscription = client.ListenToNotifications(new RequesterId { Id = MY_ID });

await foreach(var notification in subscription.ResponseStream.ReadAllAsync())
{
Console.WriteLine($"[{notification.Sent.ToDateTime().ToLocalTime().ToLongTimeString()}][{DateTime.Now.ToLongTimeString()}] Notification from {notification.From}: {notification.Message}");
}
const string MY_ID = "ConsoleListener";

using var channel = GrpcChannel.ForAddress("https://localhost:7261/");
var client = new Greeter.GreeterClient(channel);

var subscription = client.ListenToNotifications(new RequesterId { Id = MY_ID });

await foreach(var notification in subscription.ResponseStream.ReadAllAsync())
{
Console.WriteLine($"[{notification.Sent.ToDateTime().ToLocalTime().ToLongTimeString()}][{DateTime.Now.ToLongTimeString()}] Notification from {notification.From}: {notification.Message}");
}
When attempting the run the docker-compose via Rider, I get an InvalidOperationException:
Unhandled exception. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the
default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-cert
s https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken
cancellationToken)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at Program.<Main>$(String[] args) in /src/GrpcServer/Program.cs:line 19
Unhandled exception. System.InvalidOperationException: Unable to configure HTTPS endpoint. No server certificate was specified, and the
default developer certificate could not be found or is out of date.
To generate a developer certificate run 'dotnet dev-certs https'. To trust the certificate (Windows and macOS only) run 'dotnet dev-cert
s https --trust'.
For more information on configuring HTTPS see https://go.microsoft.com/fwlink/?linkid=848054.
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Reload()
at Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load()
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken
cancellationToken)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at Program.<Main>$(String[] args) in /src/GrpcServer/Program.cs:line 19
Maybe this is a certificate issue? Why is it behaving differently in VS?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Denis
Denis13mo ago
Thank you for the elaborate answer @TeBeCo, let me read through and wrap my head around it I suppose one of them was supposed to be a client, and not two servers Wow this is insanely compliment. But I suppose I have no other choice
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Denis
Denis13mo ago
The goal for this application in its current state is to: - use docker deployment for testing purposes - be capable of deploying to the cloud - be able to deploy to a on-premises environemnt
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Denis
Denis13mo ago
yeah, that makes sense But a real domain isn't something I can get, afaik
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Denis
Denis13mo ago
I mean that this project will be deployed to multiple customers - should I be the one providing the certificate? those customers will prefer on-premises for now, so I cannot use a complete cloud solution for the start
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Denis
Denis13mo ago
https://learn.microsoft.com/en-us/aspnet/core/security/docker-https?view=aspnetcore-7.0 I suppose I should follow this. Thank you, for explaining everything in detail!
Hosting ASP.NET Core Images with Docker over HTTPS
Learn how to host ASP.NET Core Images with Docker over HTTPS
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Accord
Accord13mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
acookook
acookook5mo ago
May just be the same question, on which I get a different error, seen on this image. So, I have a microservice where I can also retrieve data via gRPC, but the thing only works locally with developer certificates. When I call the gRPC endpoint running from a Docker container, I get the following exception: [link to exception]. At this point, I honestly don't understand exactly what I need to do, or rather, I know I need to: Generate a certbot certificate for the specific microservice. Include this certificate in the Docker image so that I can somehow get around Github CI (okay, I could just push the dev Docker image, but that's not correct). Ensure that it runs on the Kubernetes cluster. I'm already having trouble just generating the certificate on the Docker container. All the guides require me to run docker-compose and do something else, which in my case (as far as I understand) is not applicable. It's clear to me that I don't understand certain things, but I'm interested in where (aside from official documentation) I can learn more. I would just like to run my microservices inside of the docker containers on a kubernetes cluster.
No description
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
acookook
acookook5mo ago
Yeah, thought so. Okay, i'll Just open a new thread.
Want results from more Discord servers?
Add your server
More Posts
❔ How to "mute and resume" in RiderWhen I have an exception breakpoint for all CLR exceptions, when the debugger halts for an exception❔ Best way to set up a websocket and API to access the data?I'm working on a website that gathers data through a websocket on the backend, using raw UDP packets❔ Blazor WebassemblyTrying to put an image into a canvas so I can use coordinates to place images in different spots. Tr❔ Log into minecraft with xbox/microsoft apiI was wondering how to authenticate a Minecraft account with Microsofts new account system and if th❔ optimizationSincere question about optimization here... The RenderFirstTab() method is called in an infinite lo❔ How to instantiate derived class when base class requires args?Hey, I'll post the code below but I don't think it'll be necessary as I'm pretty sure I know what th❔ Not sure should I leave the automatic table alteration (postgres EF Core 3.0 to EF Core 6.0)You can see on the picture that EF Core has added some non intentional AlterColumn entries. I guess ❔ Writing VS Extension to Support Language with TextMate Grammar FileHello, I am trying to write extension to support BNF(Backus–Naur form) metalanguage files. I am try❔ Change trigger behavior from code behind(!)Hello again. I am still making a chess game using wpf&wcf. And the problem is that entire board is g❔ Getting SQL data from a relationship tableHello, for my school assignment I have to make a winforms app. Currently I have 3 tables in my SQL D