'Accessing docker internal ports from the host

I am running a server in a kali container in docker. Is there any way I can access all the ports of the container using the docker ip? Suppose the server spins up a random port every time I start it in the container.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source