Repository navigation
Closed
Description
- This is a bug report
- This is a feature request
- I searched existing issues before opening this one
Expected behavior
As in docker-for-mac and docker-for-windows, inside a container, the DNS name host.docker.internal resolves to an IP address allowing network access to the host (roughly the output of ip -4 route list match 0/0 | cut -d' ' -f3 inside the same container).
Actual behavior
host.docker.internal resolves to nothing
Steps to reproduce the behavior
Execute docker run --rm alpine nslookup host.docker.internal
See it returns nslookup: can't resolve 'host.docker.internal': Name does not resolve
Output of docker version:
Client:
Version: 18.03.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:10:09 2018
OS/Arch: linux/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.0-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:08:36 2018
OS/Arch: linux/amd64
Experimental: false
Output of docker info:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 1
Server Version: 18.03.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.13.0-37-generic
Operating System: Ubuntu 17.10
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.947GiB
Name: rob-VirtualBox
ID: 3L2C:BTV3:TQO2:4SAG:XVW5:744G:MPWQ:62FK:56DP:KH3Z:EQ7Z:TBR5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
Additional environment details (AWS, VirtualBox, physical, etc.)
Running Ubuntu in VirtualBox 5.2.8 on OS/X 10.13.4
Reacted by bscheshirwork, Misha Bergal, Ze Chen, Martin Philipponneau, Juan Tenorio Arzola, Nat Zimmermann, Juan Treminio, Shakti Das, Rodolfo Toledo, Thomas LÉVEIL and 1368 more
Reacted by {16/7} and Dmytro Tiapukhin
Reacted by Dr. Juan Miguel Cejuela, Arno DUBOIS, David Naber, Michael R Bucher, Samuele Kaplun, k1w1m8, Igor Katrayev, Antonio Malcolm, João Paulo dos Santos Portela, Glavin Wiechert and 163 more
Reacted by Oleksandr Gornostal, Brian Belhumeur, Fei, Matthieu Joannon, valentinewallace, Wesley, Grant Henke, Konstantin Shpolvind, Dror Weiss, Victor Gazotti and 67 more
Reacted by Jacob Brown, Matthieu Joannon, valentinewallace, Janne Jaanila, Wesley, Grant Henke, Konstantin Shpolvind, Timur Saliakhutdinov, Shelepov G, Victor Gazotti and 79 more
Metadata
Metadata
Assignees
Labels
No labels
Activity
bscheshirwork commentedon Apr 2, 2018
same situation. I want to use this in docker-compose.yml for replace
remote_hostbscheshirwork commentedon Apr 2, 2018
https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds
I want to connect from a container to a service on the host
The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host.
The gateway is also reachable as gateway.docker.internal.
JuxhinDB commentedon Apr 11, 2018
Same situation, when taking a closer look at
/etc/hostsI notice the following:Which suggests that it's just setting it to a random ID rather than
host.docker.internalwhich is what I need.Zomis commentedon Apr 15, 2018
When I tried to find out how to connect to host from Docker I found this question/answer on Stack Overflow: https://stackoverflow.com/a/43541732/1310566
I was not aware at the time that it only applied to macOS and Windows (it was just recently edited)
atolia commentedon May 1, 2018
While this feature not on linux I use
bscheshirwork commentedon May 2, 2018
@atolia
This look like work with
docker-compose exec weband don't work withdocker-compose run --rm --entrypoint /bin/bash webhernandev commentedon May 8, 2018
Mimic on that can be done with:
Notice @atolia already provided a similar solution, but he is not considering non-privileged default
USER, this one will work for non-root images with passwordless sudo available, for images where default user isroot, just remove the sudo part.This command will make
docker.host.internalavailable regardless of the Docker version OR execution mode. I'm using this on entrypoint files.acuthbert commentedon May 15, 2018
Firstly - docker is an amazing tool and so thank you for all who work tirelessly on it! As a leader of a large mixed team of linux and mac engineers this has been one of the biggest "why did we leave vagrant" questions I get hammered about when we called time on vagrant. It is very frustrating that this exists on mac and windows and not linux. We need connect back for xdebug and for letting selenium running in a container to access local urls for acceptance testing. This difference is bloating our build scripts with more and more fragility so it would be great if this was standardised. Is it not a worry if the same version of docker engineer on the 3 platforms can deviate in feature set?
FX-HAO commentedon May 16, 2018
docker.host.internalis still unavailable on my mac. And I can't connect to my host with172.17.0.1.My docker version:
chaospixel commentedon May 16, 2018
In case you missed it: docker.for.mac.host.internal and docker.for.mac.localhost do work - but only on docker for mac...
FX-HAO commentedon May 16, 2018
Older aliases are deprecated in favor of this one. And I tried them, not working.
mnd999 commentedon May 16, 2018
Not working here either (unsurprisingly).
mnd999 commentedon May 16, 2018
@JuxhinDB it's not a random number, it's the container id. Still not useful though.
jcoutch commentedon May 18, 2018
I'm running a
microsoft/dotnet-frameworkcontainer on a Windows host (v18.03.1-cd-win65 17513), andhost.docker.internaldoes not work.kunal-bhatia commentedon May 22, 2018
Any idea, when will linux support for connecting to special DNS will be fixed?
284 remaining items
joffrey-bion commentedon Nov 24, 2022
Sorry to bring this back, but how can I get the Docker daemon itself to reach the host?
I'm trying to do
docker login localhost:8390from the host machine, where the registry is a local server that does NOT run in a container. On Windows and macOS, I needhost.docker.internalbecause the daemon is running in the Linux VM, so when reaching the registry running on the host it needs to reach the host OS. I'd like to be able to use the same code and address on all OSes.Is there any configuration I can do on Linux so the daemon itself knows about
host.docker.internal? I cannot--add-hostto the daemon, right?tomu123 commentedon Nov 29, 2022
Also the only documentation that mentions it says the host-gateway defaults to the default bridge ip instead of saying that it defaults to the docker internal host address which makes it really confusing even if you find this piece of documentation. I'm not really sure they mean the same since I'm not really knowledgeable in networking. Hopefully anyone could give me insight on that and they update the documentation soon.
droplet-js commentedon Dec 21, 2022
any news update?
why docker in linux must add ' --add-host="host.docker.internal:host-gateway" ', and docker in mac not need '--add-host'?
droplet-js commentedon Dec 21, 2022
how to setup docker in linux?
dimitri-lda commentedon Feb 4, 2023
Thanks! That's helped me. I had 172.22.0.5
feat: update xdebug setup
zeorin commentedon Apr 13, 2024
On Linux with Docker version
24.0.5, the magic variablehost-gatewayrefers to the default bridge network only. Usingextra_hoststo explicitly sethost.docker.internaltohost-gatewaywill set it to the default bridge network's host IP address, even if the container is not connected to that network.I worked around this by adding
To the
commandindocker-compose.yml.feat: Adds docker metrics to prometheus scraping
Add host.docker.internal to docker-compose.yml
Add host.docker.internal to docker-compose.yml
Add host.docker.internal to docker-compose.yml
Add host.docker.internal to docker-compose.yml
nyetwurk commentedon Aug 7, 2025
will this work if using ansible and not docker-compose?
UNOMI-919: Refactor the UNOMI startFeatures configuration to use a Karaf