Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

host.docker.internal does not resolve properly #2965

Closed
2 tasks done
128keaton opened this issue Jun 1, 2018 · 55 comments
Closed
2 tasks done

host.docker.internal does not resolve properly #2965

128keaton opened this issue Jun 1, 2018 · 55 comments

Comments

@128keaton
Copy link

128keaton commented Jun 1, 2018

  • 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.

@128keaton 128keaton changed the title host.docker.internal does not resolve to anything host.docker.internal does not resolve properly Jun 1, 2018
@deedree
Copy link

deedree commented Aug 21, 2018

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

@PeterBengtson
Copy link

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.

@128keaton
Copy link
Author

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

@allyjweir
Copy link

Has there been any progress on this issue?

@findstar
Copy link

findstar commented Oct 5, 2018

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

@anaerobic
Copy link

anaerobic commented Oct 30, 2018

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.

@FernandoMiguel
Copy link

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.

@ror6ax
Copy link

ror6ax commented Nov 6, 2018

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

@PeterBengtson
Copy link

PeterBengtson commented Nov 6, 2018 via email

@ror6ax
Copy link

ror6ax commented Nov 6, 2018 via email

@qoomon
Copy link

qoomon commented Nov 8, 2018

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

@carusology
Copy link

carusology commented Nov 8, 2018

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?

@deedree
Copy link

deedree commented Nov 16, 2018

Reinstall fixed it for me. Thanks!

@sonerd
Copy link

sonerd commented Nov 22, 2018

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

@yooouuri
Copy link

yooouuri commented Dec 14, 2018

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

@keithy
Copy link

keithy commented Jan 30, 2019

I found this in /etc/hosts

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

@docker-robott
Copy link
Collaborator

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

@Bulletninja
Copy link

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`

@liufuyang
Copy link

liufuyang commented Jul 30, 2019

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

@128keaton
Copy link
Author

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.

@liufuyang
Copy link

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 ...

@sanathkumarbs
Copy link

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```

@ilkerc
Copy link

ilkerc commented Aug 22, 2019

Same here, worked around with bridge network

@Rakk4403
Copy link

Rakk4403 commented Sep 1, 2019

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

@geerlingguy
Copy link

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).

@geerlingguy
Copy link

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
Copy link

g1eb commented May 8, 2020

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

@chasen-bettinger
Copy link

chasen-bettinger commented Aug 14, 2020

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

@mbreevoort
Copy link

@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
Copy link

@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.

@mbreevoort
Copy link

mbreevoort commented Aug 19, 2020

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?

@shree007
Copy link

shree007 commented Oct 4, 2020

I have solved in Docker version 19.03.12 and MacOS Catalina 10.15.7

I found "kubernetes.docker.internal"

@soarpatriot
Copy link

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

@offspring
Copy link

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

@johnnyhuy
Copy link

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
Copy link

sj26 commented Feb 19, 2021

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

@mbreevoort
Copy link

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
Copy link

sj26 commented Feb 26, 2021

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.

@RohitRox
Copy link

RohitRox commented May 9, 2021

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
Copy link
Contributor

djs55 commented Jun 10, 2021

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 djs55 closed this as completed Jun 10, 2021
@nahum-litvin-hs
Copy link

nahum-litvin-hs commented Jun 29, 2021

@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
Copy link
Contributor

djs55 commented Jul 1, 2021

@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!

@nahum-litvin-hs
Copy link

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

@topaz2
Copy link

topaz2 commented Jul 16, 2021

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

@mystix
Copy link

mystix commented Jul 26, 2021

@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.

@erald14
Copy link

erald14 commented Aug 9, 2021

I have solved in Docker version 19.03.12 and MacOS Catalina 10.15.7

I found "kubernetes.docker.internal"

this works for me :)

@docker-robott
Copy link
Collaborator

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

@docker docker locked and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests