How is the mapping done from a registry to index server?

How does Docker map a registry to index server URL? Is the index server URL hardcoded in code for registry? If yes, then I guess it’s not possible to use a different index server for private registry, is it?

So, there is no mapping - in terms of the relationship between the two, Docker registry is slightly different from Docker index, mostly around specifying the FROM field. You can’t really do anything with the Docker index, so I wouldn’t worry about it much. Here is a more comprehensive answer on private registries and the Docker index, hopefully this helps answer the other parts of your question.