Can i add a port binding to a docker container while debugging in Visual Studio?

I’m doing a PoC using dockers and .net 5. The idea is to create a console app or worker service that opens a TCP port and start listening for some specific traffic. If i test it outside of dockers it works but when i try to debug using dockers, the container is run without any port binding. Without the port binding the program does not receive any connection.

This happens with Background workers or Console Apps projects. Meanwhile i tried using the project “Container Application for Kubernetes” and removed all the web code and put mine own code. With this project, VS binds a random port to the exposed port.

Is there anyway i can add a port binding manually to a visual studio debugging process?

Source: StackOverflow