Reputation: 552
How can I connect to localhost mysql server from a docker container on macOS ? One way to do it using --add-host but that requires me to pass some name like "myhost". Is there any way in macOS so that references to localhost from inside docker container actually refer to docker host ?
Upvotes: 7
Views: 7708
Reputation: 103
use host.docker.internal
to connect to the host running the Docker. this works From docker version 18.03 onwards only and This is for development purposes and will not work in a production environment outside of Docker Desktop for Mac. ( refer the page https://docs.docker.com/docker-for-mac/networking/ for more info )
sample connection string for oracle, jdbc:oracle:thin:@host.docker.internal:1521/orcl
From inside of a Docker container, how do I connect to the localhost of the machine?
Upvotes: 5
Reputation: 2754
On MacOS docker provide special DNS name docker.for.mac.localhost
which will resolve to the internal IP address used by the host.
Upvotes: 9
Reputation: 3639
You should be able to connect to MySql running on host machine using host machine actual IP address. In MacOS, try to find your ip by command ifconfig
. Mostly using IP assigned to en0
i.e. your ethernet interface should work. Just call that IP from within your container.
*localhost or 127.0.0.1 or 0.0.0.0 doesnt call host machine as they are local to container itself.
Upvotes: 0