How to resolve the host operating system 'localhost' address from within a container?
You are correct in that using localhost within the container is referencing the container, and not your network.  You could use inspect, find the ip, and hardcode the ip.  However, a simpler and cleaner solution would be to utilize Docker's network features.  When you run the containers you can put the containers inside a defined network.  Containers in this network can resolve requests to other containers using their container name instead of an ip (e.g. Server=container2).

Docker Network Documentation