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 ?
-
--network="host" does not work on macOS . – rigal Mar 28 '17 at 14:52
3 Answers
On MacOS docker provide special DNS name docker.for.mac.localhost
which will resolve to the internal IP address used by the host.

- 2,574
- 18
- 26
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?

- 93
- 2
- 8
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.

- 3,423
- 1
- 21
- 23
-
yes I was able to connect to docker host mysql server using ip . But as default mysql installation binds to 127.0.0.1 , I have to edit this in config file and added a new user with appropriate permissions to connect from container app . – rigal Apr 19 '17 at 20:43