MacOS – Not able to resolve the domain name on browser

hostsmacosNetworkweb-browser

I am using docker for application and modified the hosts file and added domain name on local browser. I added in hosts:

    127.0.0.1 xyz.com

but when I am trying to open from browser getting the following error:

This page isn’t working

xyz.com is currently unable to handle this request.
HTTP ERROR 500

What I am doing wrong?
Same application running in different OS like windows and ubuntu but here I am facing issues.

Best Answer

If you are modifying /etc/hosts in the Docker container itself, then only processes within the Docker container are going to be able to resolve that domain locally.

Thus, if you are using a browser on your Mac to access a port exposed by Docker, it knows nothing about the DNS override and will try to hit the real site -- which likely explains the message you're getting.

You need to append to your Mac's /etc/hosts. (You'll need sudo, a text editor, and to ensure you left the file owner, group, and permissions unchanged when you're done.)