Today I learned, that I can use the address `host.docker.internal` to connect to the host from within a Docker container.
>The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name `host.docker.internal` which resolves to the internal IP address used by the host. *This is for development purpose and will not work in a production environment outside of Docker Desktop for Windows / Mac*.
3 thoughts on “TIL host.docker.internal”
Yup, very useful. I found about this the other week when I was trying to PoC Vault Integration on a local kubernetes cluster. Works great!
Note that it only works on the Docker for Windows / Mac.
On Linux it’s useless.
This reminds me of the dind “Docker in Docker” idea. I don’t know what security issues there might be, but inception isn’t hard. YSMV (your socket may vary).
command: sh -c “while :; do docker container ls; sleep 15; done”
# this service will have access to the same docker instance that ran it