Could not connect to debugging client

When the docker container is lifted. The message falls out

Xdebug: [Step Debug] Could not connect to debugging client. Tried: host.docker.internal:9003 (fallback through xdebug.client_host/xdebug.client_port) :-(

Docker-compose.yml chapter php

php-fpm-back:
build:
context: ./docker/
dockerfile: dev/back/php-fpm/Dockerfile
volumes:
- ./back:/app
environment:
PHP_IDE_CONFIG: ${PHP_IDE_CONFIG}
APP_DEBUG: 1
networks:
- together

php-cli-back:
build:
context: ./docker/
dockerfile: dev/back/php-cli/Dockerfile
environment:
APP_DEBUG: 1
volumes:
- ./back:/app
networks:
- together

docker file php-cli-back

FROM php:8.0.8-cli-alpine

RUN apk add --no-cache unzip

RUN apk add --no-cache autoconf g++ make \
&& pecl install xdebug-3.0.1 \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable xdebug

RUN apk add --no-cache postgresql-dev fcgi \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo_pgsql

RUN mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini

COPY ./common/back/php/conf.d /usr/local/etc/php/conf.d

COPY ./dev/back/php/conf.d /usr/local/etc/php/conf.d
#COPY ./common/wait-for-it /usr/local/bin/wait-for-it
#RUN chmod 555 /usr/local/bin/wait

ENV COMPOSER_ALLOW_SUPERUSER 1

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/bin --filename=composer --quiet

WORKDIR /app

docker file php-fpm

FROM php:8.0.8-fpm-alpine

ENV XDEBUG_VERSION 3.0.4

RUN apk add --no-cache autoconf g++ make \
&& pecl install xdebug-3.0.1 \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable xdebug

RUN apk add --no-cache postgresql-dev fcgi \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo_pgsql

RUN mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini

COPY ./common/back/php/conf.d /usr/local/etc/php/conf.d
COPY ./dev/back/php/conf.d /usr/local/etc/php/conf.d
COPY ./dev/back/php-fpm/conf.d /usr/local/etc/php/conf.d

WORKDIR /app

COPY ./dev/back/php-fpm/entrypoint.sh /usr/local/bin/docker-php-entrypoint
RUN chmod +x /usr/local/bin/docker-php-entrypoint

entripoin.sh

FROM php:8.0.8-fpm-alpine

ENV XDEBUG_VERSION 3.0.4

RUN apk add --no-cache postgresql-dev fcgi git \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& git clone --branch $XDEBUG_VERSION --depth 1 https://github.com/xdebug/xdebug.git /usr/src/php/ext/xdebug \
&& docker-php-ext-configure xdebug --enable-xdebug-dev \
&& docker-php-ext-install pdo_pgsql xdebug \
&& apk del git

RUN mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini

COPY ./common/back/php/conf.d /usr/local/etc/php/conf.d
COPY ./dev/back/php/conf.d /usr/local/etc/php/conf.d
COPY ./dev/back/php-fpm/conf.d /usr/local/etc/php/conf.d

WORKDIR /app

COPY ./dev/back/php-fpm/entrypoint.sh /usr/local/bin/docker-php-entrypoint
RUN chmod +x /usr/local/bin/docker-php-entrypoint


phpstorm
Plese help me!

2 comments
Comment actions Permalink

host.docker.internal doesn't work on Linux: https://github.com/docker/for-linux/issues/264
You can use this as a workaround, or use your main network interface's (eth0 or whatever) IP address.

0
Comment actions Permalink

I forgot to upload the file entrypoin.sh which for php-fpm-back solves this problem here it is

#!/bin/sh
set -e

HOST_DOMAIN="host.docker.internal"
if ! ping -q -c1 $HOST_DOMAIN > /dev/null 2>&1
then
HOST_IP=$(ip route | awk 'NR==1 {print $3}')
# shellcheck disable=SC2039
echo -e "$HOST_IP\t$HOST_DOMAIN" >> /etc/hosts
fi

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- php-fpm "$@"
fi

exec "$@"

0

Please sign in to leave a comment.