docker容器和phpStrom之间xdebug调试代码

docker container 通信

容器之间通信

容器之间三种方式通信:https://www.cnblogs.com/CloudMan6/p/7096731.html

宿主机链接容器的服务

通过端口映射,本地端口路由转到容器内端口

容器链接宿主机的服务

通过网关IP地址 或者 host.docker.internal 要docker版本大于v18.03

php容器安装xdebug

docker exec -it {container id}
pecl install xdebug 
或者 安装指定版本
pecl install channel://pecl.php.net/xdebug-2.6.0

用vim或者echo 信息到php.ini文件中
[xdebug]
zend_extension=xdebug.so
xdebug.remote_handler = "dbgp"
xdebug.idekey="owen"
xdebug.remote_enable=On
xdebug.remote_host= "host.docker.internal" //此host可以链接到宿主机
xdebug.remote_port=9010  // 此端口为phpStrom配置的xdebug端口
xdebug.remote_autostart=1

容器链接宿主机

  • 通过host.docker.internal链接

测试通信是否成功

在宿主机使用tcpdump抓包

访问容器中的web页面或者nc通信息

需要想清楚的地方

windows和mac系统,docker的真宿主机是虚拟机中的linux系统
所以,链接到网关通通信宿主机的方式行不同。
安装ping命令后, 在容器中ping host.docker.internal 可以查看它的IP什么
在mac或windows系统找不到对应的网关配置,因为它其实是你虚拟机在linux的网关配置。
在windows和mac上使用docker一定要记清楚
(windows|mac)os -> linux -> docker

参考文章

How to access host port from docker container

https://stackoverflow.com/questions/31324981/how-to-access-host-port-from-docker-container/31328031

容器间通信的三种方式 - 每天5分钟玩转 Docker 容器技术(35)

https://www.cnblogs.com/CloudMan6/p/7096731.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值