docker/for-mac

host.docker.internal does not resolve properly

128keaton opened this issue ยท 55 comments

  • I have uploaded Diagnostics
  • I have tried with the latest version of my channel (Stable or Edge)
  • Diagnostics ID: 80B22EC8-EBD9-42FA-ABC5-67F685FD5DD1

Expected behavior

host.docker.internal to resolve properly

Actual behavior

host.docker.internal does not resolve to anything.

Information

  • macOS Version: 10.12.6

Diagnostic logs

Docker for Mac: version: 18.03.1-ce-mac65 (dd2831d4b7421cf559a0881cc7a5fdebeb8c2b98)
macOS: version 10.12.6 (build: 16G1314)
logs: /tmp/80B22EC8-EBD9-42FA-ABC5-67F685FD5DD1/20180601-094343.tar.gz
[OK]     vpnkit
[OK]     vmnetd
[OK]     dns
[OK]     driver.amd64-linux
[OK]     virtualization VT-X
[OK]     app
[OK]     moby
[OK]     system
[OK]     moby-syslog
[OK]     kubernetes
[OK]     files
[OK]     env
[OK]     virtualization kern.hv_support
[OK]     osxfs
[OK]     moby-console
[OK]     logs
[OK]     docker-cli
[OK]     disk

Steps to reproduce the behavior

(simple demo)

  1. docker run --rm alpine nslookup host.docker.internal
  2. screen shot 2018-06-01 at 9 49 04 am

(use in dev)


services:
  php:
    build:
      context: dev/docker/php
      args:
        TIMEZONE: ${TIMEZONE}
        LOCAL_USER_ID: ${LOCAL_USER_ID}
    networks:
      main:
        aliases:
          - php
    environment:
      COMPOSER_ALLOW_SUPERUSER: 1
    volumes:
      - nfsmount:/var/www/site
      - ~/.ssh:/home/www-data/.ssh
volumes:
  nfsmount:
    driver: local
    driver_opts:
      type: nfs
      o: addr=addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3
      device: ":${PWD}"

Running docker-compose up with this configuration results in:
ERROR: for php Cannot create container for service php: error resolving passed in nfs address: lookup addr=host.docker.internal: no such host

I have tried rebooting and resetting Docker. I'd rather not update to 10.13.

I've got the same problem on Mac OS Mojave 10.14. docker system prune --volumes as mentioned here: #2705 didn't work either.

I have exactly the same problem. It makes networking between services impossible to set up on the Mac. I add my vote for a quick fix, as this is a showstopper in many Mac dev projects.

@PeterBengtson I had to move back to using Vagrant while the rest of the team happy enjoys Docker because of this issue.

Has there been any progress on this issue?

I have exactly the same problem. on Mac OS Mojave.

Same problem on OSX Mojave (10.14) using Version 18.06.1-ce-mac73 (26764)

However, docker.for.mac.host.internal does resolve to the correct IP.

I'm using this with latest stable Docker and docker-compose with NFS on the latest macos and it works fine..
I'll retest today to be sure.

Hi @PeterBengtson @128keaton, can you please let us know what is the status here? Thanks a lot.

have a look at https://github.com/qoomon/docker-host as a workaround

I also had this issue. Reinstalling with the latest stable version (18.06.1-ce-mac73) caused the host.docker.internal DNS entry to resolve to the host machine in my containers. I am also running macOS 10.14 (Mojave).

My original installation was pretty old (I'd applied updates, but never reinstalled anew) that had some dns haxin' lingering as described in this issue. Maybe it was related?

Reinstall fixed it for me. Thanks!

I have the same problem on macOS (Mojave) with docker (18.09) and also (18.06.1-ce).
host.docker.internal can not be accessed from docker container.

A ping to host.docker.internal from the docker container works:
docker exec -it <id of your container> /bin/bash
and then
ping host.docker.internal
resolves to:
PING host.docker.internal (192.168.65.2) 56(84) bytes of data

But
docker run --rm alpine nslookup host.docker.internal
returns

nslookup: can't resolve '(null)': Name does not resolve

Name:      host.docker.internal
Address 1: 192.168.65.2

Same issue here as @sonerd

$ docker run --rm alpine nslookup host.docker.internal
nslookup: can't resolve '(null)': Name does not resolve

Name:      host.docker.internal
Address 1: 192.168.65.2
$ docker run --rm alpine ping host.docker.internal
PING host.docker.internal (192.168.65.2): 56 data bytes
64 bytes from 192.168.65.2: seq=0 ttl=37 time=0.257 ms
64 bytes from 192.168.65.2: seq=1 ttl=37 time=0.569 ms
64 bytes from 192.168.65.2: seq=2 ttl=37 time=0.561 ms
64 bytes from 192.168.65.2: seq=3 ttl=37 time=0.562 ms
^C
--- host.docker.internal ping statistics ---
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.257/0.487/0.569 ms

Docker version 18.09.0, build 4d60db4

I found this in /etc/hosts

172.16.238.1 docker.for.lin.host.internal
172.16.238.1 docker.for.lin.localhost

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale comment.
Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle stale

I have the same problem in macos mojave 10.14.5 (18F132) and Docker version 19.03.0-rc2, build f97efcc:

`> $ docker run --rm alpine nslookup host.docker.internal

nslookup: can't resolve '(null)': Name does not resolve
nslookup: can't resolve 'host.docker.internal': Name does not resolve`

I seem to have this issue as well. What should I do?...
With docker engine 19.03.1

This issue has been up/alive for over a year. That, combined with the lack of documentation on Docker's FS implementation on mac (sucks!) really makes you think if docker is the right move anymore.

I can't understand why this simple issue cannot be solved.... for now it seems that I just need to use 192.168.65.2 and it works, instead of using host.docker.internal or something like docker.for.mac.localhost ...

Having the same exact issue. Docker Desktop 2.1.0.1 (37199) stable.

 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        74b1e89
 Built:             Thu Jul 25 21:18:17 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.1
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.5
  Git commit:       74b1e89
  Built:            Thu Jul 25 21:17:52 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683```

Same here, worked around with bridge network

Any update?
I have same issue and It's over the year! ๐Ÿคš

$ docker-compose run -e DISPLAY=$MY_HOST_IP:0 myapp   // works well
$ dokcer-compose run -e DISPLAY=host.docker.internal:0 myapp   // cannot connect error

and ping works well on container inside.

root@d02807ed1072:/# ping host.docker.internal
PING host.docker.internal (192.168.65.2) 56(84) bytes of data.
64 bytes from 192.168.65.2: icmp_seq=1 ttl=37 time=1.59 ms
64 bytes from 192.168.65.2: icmp_seq=2 ttl=37 time=0.452 ms

with Docker version 19.03.1, build 74b1e89

seems like passing host.docker.internal into container as environment is considered as a litteral word not as a resolve target. cause ping works in container bash.

Still having the same issue on

  • MacOS 10.14.6
  • Docker version 19.03.2 and 18.09.2, build 6247962.
  • Docker Desktop: Version 2.0.0.3 (31259)
  • Docker machine: 0.16.1
rfay commented

Just a note for folks in this issue: I just had a user who thought they were using Docker Desktop (which provides host.docker.internal) but they were actually accessing an old docker-machine running in Docker Toolbox via the environment variable DOCKER_HOST, and I don't believe Docker Toolbox ever provides host.docker.internal. So... you shouldn't need or have DOCKER _HOST if you're using Docker Desktop, and check carefully that all vestiges of Docker Toolbox are gone.

Having same issue with:

MacOS 10.14.6
Docker Version 19.03.5
Docker Desktop: Version 2.1.0.5 (40693)
Docker Machine: 0.16.2

It's been more than a year! You've got to be kidding!

After removing custom dns entries from my docker advanced daemon settings host.docker.internal does finally resolve again.

After removing custom dns entries from my docker advanced daemon settings host.docker.internal does finally resolve again.

Thanks this fixed the problem
If you need a custom dns try to add the first ip as dns. So if the subnet is 192.168.65.0/24 under Resources->Network then the dns is probably 192.168.65.1
Example with google dns:

{ 
"dns": [ "8.8.8.8", "192.168.65.1"] 
}

Maybe adding the docker dns may also fix the problem, can somebody try this?

Same issues.

How do you do this?

After removing custom dns entries from my docker advanced daemon settings host.docker.internal does finally resolve again.

I've been running into this issue as well, when trying to use NFS for filesystem mounts. No resolution, tried anything suggested in this issue so far, short of completely uninstalling and reinstalling Docker for Mac (on Catalina, 10.15.3).

Well that's embarrassing... I spent 30 minutes on this, and finally re-read my error message:

ERROR: for drupal  Cannot create container for service drupal: error resolving passed in nfs address: lookup addr=host.docker.internal: no such host
ERROR: Encountered errors while bringing up the project.

The problem was I had copied and pasted the config from a gist or blog post to get NFS configured in my docker-compose file, and it had the format:

o: addr=addr=host.docker.internal,rw,nolock,hard,nointr,nfsvers=3

So someone must've fat-fingered that in whatever post/example I was reading. I deleted the extra =addr, and now I can get connected.

g1eb commented

Going into the preferences and removing this from the dns entry from the docker engine configuration fixed this issue on Mojave 10.14.6.

Running docker container exec -it container sh

and then once in the docker container running: nslookup host.docker.internal

returns:

Server:		192.168.65.1
Address:	192.168.65.1:53

Non-authoritative answer:
Name:	host.docker.internal
Address: 192.168.65.2

** server can't find host.docker.internal: NXDOMAIN

On the docker container my /etc/hosts file looks like this:

127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.17.0.2	eb0aec82ae7e

No reference to host.docker.internal anywhere. Any thoughts? Running Docker for Mac on macOS Catalina 10.15.1.

docker version output:


Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:22:34 2019
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:29:19 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

@chasen-bettinger it is from the docker dns, in your case 192.168.65.1

 # cat /etc/resolv.conf
# This file is included on the metadata iso
nameserver 192.168.65.1

So if the dns is not set to the internal docker dns, the hostname host.docker.internal couldn't be found

@chasen-bettinger it is from the docker dns, in your case 192.168.65.1

 # cat /etc/resolv.conf
# This file is included on the metadata iso
nameserver 192.168.65.1

So if the dns is not set to the internal docker dns, the hostname host.docker.internal couldn't be found

How do you set the DNS to the internal docker DNS? I'm confused mostly because the way the documentation is written, it seems like it should work out of the box.

The default with no dns is in the docker config should use the default docker dns. If you add other dns servers in the config you probably also need to add the default as the first (only the first 2 are used normally).
You're nslookup host.docker.internal returns the ip 192.168.65.2 of the internal dns for host.docker.internal, so what's the problem?

I have solved in Docker version 19.03.12 and MacOS Catalina 10.15.7

I found "kubernetes.docker.internal"

I can't understand why this simple issue cannot be solved.... for now it seems that I just need to use 192.168.65.2 and it works, instead of using host.docker.internal or something like docker.for.mac.localhost ...

Use ip works for me. thanks

Hmm. still broken. when
--dns=10.10.10.10
--dns-search=somedomain \

I've noticed kubernetes.docker.internal was set in my /etc/hosts file by Docker Desktop.

...
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
127.0.0.1 host.docker.internal # (NOTE) I added this
# End of section
...

That seemed to work in my case where I wanted containers to contact my localhost services, whilst allowing my client to access services via host.docker.internal like a website.

sj26 commented

I have a stock docker for mac install. I'm trying to talk to my host's http server. I'm following the advice from the documentation here:
https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds

but:

$ docker run --rm alpine nslookup host.docker.internal
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
069a56d6d07f: Pull complete 
Digest: sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be
Status: Downloaded newer image for alpine:latest
Server:		192.168.64.1
Address:	192.168.64.1:53

** server can't find host.docker.internal: NXDOMAIN

** server can't find host.docker.internal: NXDOMAIN

Why doesn't this work? Has it truly not worked since 2018?

docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., unknown)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc., v0.3.5)

Server:
 Containers: 1
  Running: 1
  Paused: 0
  Stopped: 0
 Images: 11
 Server Version: 20.10.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.19.104-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 4
 Total Memory: 1.935GiB
 Name: docker-desktop
 ID: VUUH:VANS:F3Q5:WR4O:7JPP:VBK2:MUNK:O7Z5:BMKN:4RPJ:ASU7:UWQN
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: true
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false
 Product License: Community Engine

Still works for me. Not using a VPN or something?
Here is my info

$ docker run --rm alpine nslookup host.docker.internal
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
ba3557a56b15: Pull complete 
Digest: sha256:a75afd8b57e7f34e4dad8d65e2c7ba2e1975c795ce1ee22fa34f8cf46f96a3be
Status: Downloaded newer image for alpine:latest
Server:		192.168.65.1
Address:	192.168.65.1:53

Non-authoritative answer:
*** Can't find host.docker.internal: No answer

Non-authoritative answer:
Name:	host.docker.internal
Address: 192.168.65.2
docker info

$ docker info
Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.5.1-docker)
  scan: Docker Scan (Docker Inc., v0.5.0)

Server:
 Containers: 99
  Running: 1
  Paused: 0
  Stopped: 98
 Images: 2326
 Server Version: 20.10.2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc version: ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.19.121-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.847GiB
 Name: docker-desktop
 ID: 77HL:4PZ7:HNKM:HVWM:SCLE:OS7U:Z5SO:UPED:VTSX:J5D2:GRYM:H4DK
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 42
  Goroutines: 46
  System Time: 2021-02-25T12:24:24.2661933Z
  EventsListeners: 3
 HTTP Proxy: gateway.docker.internal:3128
 HTTPS Proxy: gateway.docker.internal:3129
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: true
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Docker Engine v20.10.2
image

sj26 commented

No, I don't have any VPN or other exotic network setup, am using default DNS settings, no surprising docker config options, just pretty stock Docker for Mac.

I was also having this issue. Can't say about for all platforms, but I can confirm this issue is fixed in latest release for Apple silicon
https://docs.docker.com/docker-for-mac/apple-silicon/#fixes-since-the-apple-silicon-preview-7

djs55 commented

Thanks for the report. There was a recent bug fix in Docker Desktop 3.4.0 which should ensure that host.docker.internal resolves properly. I'll close this issue now but if it still doesn't work on 3.4.0, please upload a fresh set of diagnostics, quote the ID here and ping me. I'll take a look at the logs / re-open the ticket if necessary. Thanks!

@djs55 im on latest mac osx (intel) with latest docker and docker desktop freshly installed , doesn't help
followed every single advice here only directly using ip worked

after more research seems:
host.docker.internal works if running docker command with --add-host=host.docker.internal:host-gateway

djs55 commented

@nahum-litvin-hs Could you share a repro example? Maybe there's something in the container configuration that's a bit different. Also please upload diagnostics and quote the ID so I can take a look at the logs. Thanks!

unfortunately I have no time to reproduce, this issue already took me way off schedule.

@djs55 Same issue here on Docker Desktop for mac 3.5.2.
Took Diagnostics ID.
F1C961A2-EAD5-4C6C-9194-EBBA110AF7F1/20210716142936

@djs55 im on latest mac osx (intel) with latest docker and docker desktop freshly installed , doesn't help
followed every single advice here only directly using ip worked

after more research seems:
host.docker.internal works if running docker command with --add-host=host.docker.internal:host-gateway

I can confirm @nahum-litvin-hs 's fix works on Docker Desktop for Mac 3.5.2 (Intel, MacOS Big Sur 11.5), without which the host cannot be reached from within container.

I have solved in Docker version 19.03.12 and MacOS Catalina 10.15.7

I found "kubernetes.docker.internal"

this works for me :)

Closed issues are locked after 30 days of inactivity.
This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows.
/lifecycle locked