Connect to local macOS/Windows localhost (127.0.0.1) from within Docker Container Image


Docker access host localhost within container

If you have created a docker image, say a Ubuntu base image with Apache Tomcat and you want to access Oracle/MySQL that has been installed on your local macOS/Windows system and you are wondering how to connect your device localhost from within the Docker container, then do the below,

Solution:

Make use of host.docker.internal instead of using localhost or 127.0.0.1



Note: Works are using Docker v18.03 and above.


🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.

Follow Us: GitHub | Facebook | Twitter | Instagram