Access container by name from MacOS host

Is it possible to access container by name from MacOS host?

As a workaround, I added the container name to /etc/hosts as

127.0.0.1     my-container-name

Is there a better solution that doesn’t involve changing the hosts file?