Container to container LDAP services

I have a server with several lxd containers that run services that rely on an LDAP server. The LDAP server runs on a lxd container on different host. This all works wonderfully.

I decided to move the LDAP container to the same host running all of the containers. When I did this, the containers could not authenticate to the LDAP server.

I figured out that if I add to each container a line in their /etc/hosts pointing to the container IP of the LDAP server, all of the containers can reach the LDAP server.

I don’t like relying on populating the /etc/hosts file. I would rather the external DNS server and iptables rules be used.

Is there a way to avoid this problem I’ve created for myself, given that I really do want the LDAP server on the same hardware as all of the containers?

Thanks for any help.

John