31

I want to access host IP address from a docker container on mac. I know how to do that on Linux by using the bridge0 interface. But docker for mac doesn't have bridge0. I tried to use the gateway 172.17.0.1 in a docker container but it doesn't work.

My docker for mac version is Docker version 1.13.0, build 49bf474.

I looked at this link https://github.com/docker/docker/issues/22753 but it mentions to create an alias on lo0 interface which I don't want to. Because our project is running inside docker container and I want to provides a general way without changing anything on the host.

Does anyone know how to do that in Mac?

1 Answer 1

53

From the Docker documentation :

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST

The Mac has a changing IP address (or none if you have no network access). From 17.06 onwards our recommendation is to connect to the special Mac-only DNS name docker.for.mac.localhost which will resolve to the internal IP address used by the host.

I think you'll need to upgrade your Docker For Mac version for this to work.


Updated Answer

it appears this answer has been deprecated and that you should now use host.docker.internal per docs.docker.com/docker-for-mac/release-notes/#docker-community-edition-18030-ce-mac59-2018-03-26

2
  • 16
    Let me add to my answer - it appears this answer has been deprecated and that you should now use host.docker.internal per docs.docker.com/docker-for-mac/release-notes/…
    – tunecrew
    Commented Mar 1, 2021 at 1:16
  • Instead of adding a comment to your original answer it might be more helpful to edit it because the answer is deprecated and it keeps getting downvotes.
    – Daniel B
    Commented Aug 27, 2022 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.