I'm having trouble getting my WebSocket connection to work while running my React and .NET application in Docker with HTTPS enabled using a self-signed SSL certificate. Here's a bit of context: I'm using React for the frontend, which connects to a .NET backend via WebSocket, and everything runs smoothly outside of Docker. I've set things up with Docker Compose and generated the necessary certificates. The app handles HTTP to HTTPS redirection correctly, and normal API calls work fine over HTTPS. However, the WebSocket connection is failing when I run it inside Docker, even though the same WebSocket code works perfectly when not containerized. I want to maintain the use of self-signed certificates and ensure that the WebSocket connection, using wss://, functions the same in Docker as it does locally. I'm wondering if this issue is related to the certificate setup, Kestrel configuration, or if I need to configure a reverse proxy. Any insights would be greatly appreciated!
2 Answers
It sounds like you're dealing with a tricky situation. Could you provide more details about how the WebSocket connection fails? Are you encountering timeouts, TCP errors, or HTTP errors like 500? Knowing the specific error could really help narrow things down.
In order to help you better, it’d be great if you could share some of your configuration files. Consider posting your Dockerfile, docker-compose.yml, and any reverse proxy settings on a site like GitHub Gist or Pastebin. Also, check your browser's developer tools, particularly the network tab, to see if the WebSocket requests are showing any errors or incorrect addresses.

The backend API didn't get called at all when trying to establish the WebSocket connection.