Not sure how mDNS service (Bonjour I think) is setup on macOS, but you should be able to reach it by some domain name as well (hostname.local format), once you expose your service on the public IP address.
On Linux I have my VMs run avahi (the Linux mDNS service), and I access my VMs using vmname.local instead of using hardcoded IP addresses.