問題描述
所以使用 docker 和 docker-compose 我喜歡提供內(nèi)置到容器中的工具,這樣開發(fā)團隊中的其他人就不必為設(shè)置零碎而煩惱.在這種特定情況下,我在配置 xdebug 時遇到了問題.從瀏覽器調(diào)試時,使用回連功能絕對正常.但是試圖讓 xdebug 通過容器內(nèi)的 cli 工作絕對是一場噩夢.出于某種原因,它需要(連同 remote_autostart=1)remote_host 設(shè)置來指向 docker 容器所在的網(wǎng)絡(luò).
So using docker and docker-compose I like to provide tools built into the containers so that other people in the development team don't have to struggle with setting up bits and bobs. In this specific case I'm having issues configuring xdebug. It works absolutely fine using connect back when debugging from a browser. But trying to get xdebug working through the cli inside the container is being an absolute nightmare. For some reason it requires (along with remote_autostart=1) the remote_host setting to point to the network the docker container is in.
這是我當(dāng)前的解決方案,它在我的 ~/.bashrc 中,它可以工作,但很糟糕.它的工作原理是假設(shè)網(wǎng)絡(luò) ip 只是容器 ip,但最后一位數(shù)字被替換為 1.我希望有人有更好的方法讓 xdebug 工作,或者有更好的方法來獲取網(wǎng)絡(luò) ip.
This is my current solution which is in my ~/.bashrc, and it works, but it's horrible. It works off of the assumption that the network ip will just be the containers ip but the last digit is replaced with a 1. I'm hoping someone has a better way to get xdebug working or a nicer way to fetch the network ip.
# If xdebug doesn't get provided a remote address then it will default to this. This is the case for cli debugging.
# This ip should be the network this container is running on
own_private=$(hostname -i | awk '{print $1}')
# Replaces the final number from the containers own private ip with a 1 for the network address
network="${own_private%.*}.1"
# For some reason xdebug won't work unless you give it the network ip
export XDEBUG_CONFIG="remote_host=$network"
Xdebug 設(shè)置:
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable = 1
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.show_local_vars = 0
xdebug.var_display_max_data = 10000
xdebug.var_display_max_depth = 20
xdebug.show_exception_trace = 0
xdebug.remote_autostart=1
xdebug.idekey = "PHPSTORM"
xdebug.remote_log = /srv/www/var/log/xdebug.log
xdebug.profiler_enable = 0;
xdebug.profiler_enable_trigger = 1;
xdebug.profiler_output_dir = /srv/www/var/profiler/
推薦答案
可以使用默認(rèn)網(wǎng)關(guān)的 IP 地址(即 docker0
網(wǎng)絡(luò)的 IP)從容器內(nèi)部訪問主機主機上的接口).使用ip
獲取:
The host can be accessed from within the container using the IP address of the default gateway (that is the IP of the docker0
network interface on host). Use ip
to get it:
ip route show default | awk '/default/ {print $3}'
這篇關(guān)于從容器內(nèi)獲取 docker 網(wǎng)絡(luò)的私有 ip 以配置 xdebug remote_host的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!