When starting docker a bridge network is automatically started, this network has its own ip and you have to check what is the ip of that network. If you are running it locally and used localhost, the bridge network's adress might be different from localhost and that might be why you weren't able to connect. However, using the containers' name is a much safer way to communicate between servers, docker will choose the correct address.

Subscribe to localhost