我有一个配置了 XDEBUG_CONFIG 环境变量的 docker-compose 文件,但 Xdebug 忽略了它。当我输出xdebug_info();
时,它对 xdebug.idekey 说“没有价值”。XDEBUG_MODE 虽然被正确读取。
如果我在我的 .ini 文件中设置 idekey,它就可以工作。
PHP 7.4
Xdebug 3.1.2
services:
app:
build:
context: ./docker
args:
WWWUSER: ${WWWUSER:-1000}
WWWGROUP: ${WWWGROUP:-1000}
environment:
PHP_IDE_CONFIG: "serverName=${PHP_IDE_CONFIG:-localhost}"
XDEBUG_CONFIG: "idekey=VSCODE"
XDEBUG_MODE: '${XDEBUG_MODE:-debug,develop}'
volumes:
- .:/var/www/html
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
- ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
- ./docker/php/php.ini-development:/usr/local/etc/php/php.ini
depends_on:
- mysql
- redis
- nginx
这是我完整的 docker-compose.yml
version: '3.9'
services:
app:
build:
context: ./docker
args:
WWWUSER: ${WWWUSER:-1000}
WWWGROUP: ${WWWGROUP:-1000}
environment:
PHP_IDE_CONFIG: "serverName=${PHP_IDE_CONFIG:-localhost}"
XDEBUG_CONFIG: "idekey=VSCODE"
XDEBUG_MODE: '${XDEBUG_MODE:-debug,develop}'
volumes:
- .:/var/www/html
- ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
- ./docker/php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
- ./docker/php/php.ini-development:/usr/local/etc/php/php.ini
depends_on:
- mysql
- redis
- nginx
mysql:
image: mysql:8.0
environment:
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- mysql-data:/var/lib/mysql
- ./docker/mysql:/docker-entrypoint-initdb.d
ports:
- ${FORWARD_DB_PORT:-3306}:3306
healthcheck:
test: ["CMD", "mysqladmin", "ping"]
redis:
image: redis:alpine
volumes:
- redis-data:/data
ports:
- ${FORWARD_REDIS_PORT:-6379}:6379
healthcheck:
test: ["CMD", "redis-cli", "ping"]
nginx:
image: nginx:alpine
volumes:
- .:/var/www/html
- ./docker/nginx/conf.d:/etc/nginx/conf.d
ports:
- ${NGINX_PORT:-80}:80
volumes:
mysql-data:
driver: local
redis-data:
driver: local
还有我的 Dockerfile
FROM php:7.4-fpm
# Install extensions
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions \
gd \
xdebug \
memcached \
imagick \
@composer \
pdo_mysql \
exif \
pcntl \
zip
WORKDIR /var/www/html
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
libzip-dev \
zip \
unzip \
jpegoptim optipng pngquant gifsicle \
vim \
git \
curl
RUN curl -sL https://deb.nodesource.com/setup_16.x | bash - \
&& apt-get install -y nodejs \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y yarn
# Clean
RUN apt-get -y autoremove \
&& apt-get clean
ARG WWWUSER
ARG WWWGROUP
RUN groupadd --force -g $WWWGROUP theusergroup \
&& useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u $WWWUSER theuser
USER $WWWUSER:$WWWGROUP
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]