Generate relative url in docker container

  .net-core, c#, docker

I’m trying to host my app in a docker container. The run command looks like this:

docker run -p 12345:80 my_container

There is also a code that generates relative paths like that:

var url = Url.Page("/custom", null, null, "http");

And I get url equals http://localhost:12345/custom. I’d love to get instead. It is rather weird, because user can open in theirs browser and navigate my website freely. But the url generated by Url.Page looks totally wrong.

What is a proper way to handle a case like this? It’d be great to avoid adding environment-specific code or variables.

Source: Docker Questions