Docker Community Forums

Share and learn in the Docker community.

How to access docker host from inside the container?


(Michael Teper) #1

Expected behavior

I would like to be able to have docker.local resolve to the docker host IP from inside a container. My use case is debugging a PHP app that is running inside the container using a debugger that runs in the host. The way PHP debugging works is the PHP application runs as a client that sends data to the debugger, which is the server in this scenario.

Previously, with Docker Toolbox, I used to pull the host IP and send it into the container via “extra_hosts” section of docker-compose.yml (a script would do dynamic substitution). I would love to drop this entirely.

Actual behavior

Inside the container, docker.local does not resolve.

Information

Pinata output:
OS X: version 10.11.4 (build: 15E65)
Docker.app: version v1.11.0-beta8.2
Running diagnostic tests:
[OK] docker-cli
[OK] Moby booted
[OK] driver.amd64-linux
[OK] vmnetd
[OK] osxfs
[OK] db
[OK] slirp
[OK] menubar
[OK] environment
[OK] Docker
[OK] VT-x
Docker logs are being collected into /tmp/20160427-134845.tar.gz
Most specific failure is: No error was detected
Your unique id is: 8E44C429-D414-441A-8E16-5CD83CE0681A

Steps to reproduce the behavior

  1. Start containers via docker-compose
  2. Exec bash on container (docker exec -ti bash)
  3. ping docker.local

(Tarikihr) #2

I have a similar-ish question:

How can I find the ip or host at which a container can reach the host (my Mac, not the xhyve vm)?
I need this because we have a setup with a nginx container running as a proxy for a web app we run locally for dev, the way we used to do with Docker Toolbox was simply to have nginx connect to 192.168.99.1.


(Shuanglei Tao) #3

You can mount /var/run/docker.sock to the container(-v /var/run/docker.sock:/var/run/docker.sock) and then access docker daemon via the sock, this works for me.