skip to Main Content

I am trying to install xdebug in PHP. During the build process when it gets to the COPY in the Dockerfile I get the following error message.

ERROR: Service 'php' failed to build : COPY failed: file not found in build context or excluded by .dockerignore: stat docker-php-ext-xdebug.ini: file does not exist

I have made sure that file does exist and there is not a .dockerignore file in the directory. Unless there is another .dockerignore file that is a global one. I am on a Mac

Here is my docker-compose.yml file

version: "3.7"

services:
  nginx:
    image: nginx:1.19
    ports:
      - 8080:80
    volumes:
      - ./src:/var/www/php:ro
      - ./.docker/nginx/conf.d:/etc/nginx/conf.d:ro
    depends_on:
      - php

  # PHP Service
  php:
    build: ./.docker/php
    working_dir: /var/www/php
    volumes:
      - ./src:/var/www/php
    depends_on:
      - db

  # MySQL Service
  db:
    image: mariadb:10.5-focal
    restart: always
    volumes:
      - ./mysqldata:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: laravelapp
    ports:
      - 3306:3306

  # PhpMyAdmin Service
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:5
    ports:
      - 8081:80
    environment:
      PMA_HOST: db
    depends_on:
      - db

and my Dockerfile for php service

FROM php:7.4.7-fpm
ENV PHP_IDE_CONFIG="serverName=localhost"

# Install developer dependencies
RUN apt-get update -yqq && apt-get install -y git libsqlite3-dev nano libxml2-dev libicu-dev libfreetype6-dev libmcrypt-dev libjpeg62-turbo-dev libpng-dev libcurl4-gnutls-dev libbz2-dev libzip-dev libssl-dev -yqq

# Install mcrypt for development
RUN pecl install mcrypt-1.0.4 
    && docker-php-ext-enable mcrypt

# Install xdebug for development
RUN    pecl install xdebug 
    && docker-php-ext-enable xdebug
    
#Install other php extensions
RUN    docker-php-ext-install sockets 
    && docker-php-ext-install mysqli 
    && docker-php-ext-install pdo_mysql 
    && docker-php-ext-install json 
    && docker-php-ext-install xml 
    && docker-php-ext-install zip 
    && docker-php-ext-install bz2

RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd

# Copy the configuration file into xdebug, if running phpinfo() you see the loaded file is not this one, change the path accordingly. 
COPY docker-php-ext-xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

# install composer
RUN curl --silent --show-error https://getcomposer.org/installer | php

WORKDIR /var/www/php

I have no idea why this is failing. Thank you in advance.

2

Answers


  1. Your build context is ./.docker/php, so wherever you are running docker-compose build, you need a subdirectory named .docker/php — does that exist? If you are intending for docker-compose to look somewhere else for .docker/php, you will need to remove the leading ./ and specify an absolute path.

    In other words, ${PWD}/.docker/php/docker-php-ext-xdebug.ini must exist, or you must replace ${PWD} with the desired parent directory to look in

    Login or Signup to reply.
  2. I see the question has been answered to the OP’s satisfaction, but there is one more way this error can be reported – if the file you are trying to COPY is a soft-link.

    I have this same issue and it went away when I physically copied the linked file to a "real" one.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search