Into 💆
Pre-conditions:
macOS Sierra
Docker CE Version 17.06.2-ce-mac27
PHP 7.1.8
XDebug v2.5.0
PhpStorm 2017.2
If you want to set up remote debug from your container you have 2 options:
xdebug.remote_host = %host_ip%
%host_ip%
— The IP of the machine running your IDE. It’s assumed on the same host as Docker.xdebug.remote_connect_back = on
checks$_SERVER[‘HTTP_X_FORWARDED_FOR’] and $_SERVER[‘REMOTE_ADDR’]
variables to find out which IP address to use.
You cannot use xdebug.remote_connect_back
because it takes containers’s internal IP. So xdebug.remote_host
is the only option we have.
It’s pretty simple to get host IP on Linux OS just look at : ifconfig > docker0
. Moreover you can create a fixed set of IPs for both host and containers using docker network. For instance:
docker network create -d bridge \
— subnet 192.168.0.0/24 \
— gateway 192.168.0.1 \
dockernet
Now each container can connect to the host under the fixed IP 192.168.0.1
But the docker0 interface
is not available for Docker in macOS. This interface is actually within HyperKit. So unfortunately there is no a reliable way of looping back to host for macOS. The only solution is to create your local IP’s alias to something else : sudo ifconfig lo0 alias 10.254.254.254
HowTo guide 👩💻
sudo ifconfig lo0 alias 10.254.254.254
(optional) For permanent setting up save.plist file
sudo curl -o /Library/LaunchDaemons/com.yuklia.docker_localhost_alias.plist
- build docker containers …
- add server to IDE
- configure Debug’s port in my case it’s
9002
. xDebug client will knock to this port. - configure DBGp Proxy
Bonus 🍰
If you need to get a shell of the VM that was created by HyperKit run:
screen ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty
or
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
For getting all screens run: screen -ls
For exiting screen run : screen -X -S %screen_name% kill
Once you get the tty running you can navigate to /var/lib/docker
:
Here is my Dockerfile and docker-compose versions for php:7-fpm with XDebug
So that’s all for now 😊. Hope it will save a bunch of time for someone! I will be glad to get comments and questions. Happy hacking=) 🦾