There’s a couple of ways to do this, but the easiest way would be to connect over the IP address listed in your docker0 network adapter. If that’s the case you would just use as your DB connection host. I often see this use case come up when people are beginning to move their stack over into using Docker. This could come in handy if you wanted to connect to a database that’s running on your host but isn’t running inside of a container.
![docker ip host docker ip host](https://community.kodekloud.com/uploads/db1265/original/1X/b98d743021c5cbc72c2585311258e66378b43636.png)
(See below for Docker Compose configuration.) Use your internal IP address or connect to the special DNS name which will resolve to the internal IP address used by the host.
![docker ip host docker ip host](https://miro.medium.com/max/1400/1*3eCbJFfCH9HJ-dehWvUENg.png)
Docker for Mac / Docker for WindowsĪs of Docker v18.03+ you can use the hostname to connect to your Docker host. For all platforms Docker v 20.10 and above (since December 14th 2020) On Linux, add :host-gateway to your Docker command to enable this feature. In Docker Tip #35 I wrote about connecting to your Docker host from inside of a container but a lot of things have changed since then. You may also use grep command to get just the lines matching the string 'IPAddress'. Go towards the end and look into the Networks section to get the containers IP address.
![docker ip host docker ip host](https://www.claudiokuenzler.com/graph/news/900-container-communication-host-address.png)
Let’s suppose that we have MariaDB installed on the host. Because the host and all containers are connected to that network, our application only needs to listen to it.
#Docker ip host how to
Here's how to do it on Docker for Mac, Windows and Linux. The inspect command gives you many details about the container you are inspecting. The bridge connection docker0 with IP address 172.17.0.1 is created by Docker at installation time. Updated on July 27th, 2018 in #docker Docker Tip #65: Get Your Docker Host's IP Address from in a Container Once in a while you may need your Docker host's IP address.