title: Configure Xdebug in Docker container
body: <p>I'm trying to create a docker container with PHP and Xdebug to use step debugging. I use VSCode and somehow this debugger it's not working.</p>
  <p>Apparently the Dockerfile is not been executed when I use <code>docker compose up -d</code> command. I assume that is because in the file it has a <code>COPY</code> command to copy a file (called <code>90-xdebug.ini</code>) from my project to a specific directory. And after the container is up, I check the directory and the file isn't there... then I have to execute the commands in Dockerfile manually.</p>
  <p>Anyways, after installing, I know that the installation worked because the <code>xdebug_info()</code> function works. But I don't know why VSCode can't debug it.</p>
  <p>My OS is Ubuntu 20.04.5 LTS; <em>Dockerfile</em>, <em>docker-compose.yml</em> and <em>90-xdebug.ini</em> are in project's root.</p>
  <p>My Dockerfile:</p>
  <pre><code>FROM php:7.4-apache
  
  COPY 90-xdebug.ini &quot;/usr/local/etc/php/conf.d&quot;
  RUN pecl install xdebug
  RUN docker-php-ext-enable xdebug
  </code></pre>
  <p>90-xdebug.ini:</p>
  <pre class="lang-ini prettyprint-override"><code>xdebug.mode=debug
  xdebug.discover_client_host=0
  xdebug.client_host=host.docker.internal
  </code></pre>
  <p>docker-compose.yml:</p>
  <pre class="lang-yaml prettyprint-override"><code>services:
    php-apache:
      container_name: php-apache
      image: php:7.4-apache
      build:
        context: .
        dockerfile: Dockerfile
      extra_hosts:
        - &quot;host.docker.internal:host-gateway&quot;
      volumes:
        - ./:/var/www/html/
      working_dir: /var/www/html/
      ports:
        - 3003:3003
      entrypoint: &quot;php -S 0.0.0.0:3003&quot;
  </code></pre>
  <p>launch.json inside &quot;.vscode&quot; directory:</p>
  <pre class="lang-json prettyprint-override"><code>{
      // Use IntelliSense to learn about possible attributes.
      // Hover to view descriptions of existing attributes.
      // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
      &quot;version&quot;: &quot;0.2.0&quot;,
      &quot;configurations&quot;: [
          {
              &quot;name&quot;: &quot;Listen for Xdebug&quot;,
              &quot;type&quot;: &quot;php&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;port&quot;: 9003
          },
          {
              &quot;name&quot;: &quot;Launch currently open script&quot;,
              &quot;type&quot;: &quot;php&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;program&quot;: &quot;${file}&quot;,
              &quot;cwd&quot;: &quot;${fileDirname}&quot;,
              &quot;port&quot;: 0,
              &quot;runtimeArgs&quot;: [
                  &quot;-dxdebug.start_with_request=yes&quot;
              ],
              &quot;env&quot;: {
                  &quot;XDEBUG_MODE&quot;: &quot;debug,develop&quot;,
                  &quot;XDEBUG_CONFIG&quot;: &quot;client_port=${port}&quot;
              }
          },
          {
              &quot;name&quot;: &quot;Launch Built-in web server&quot;,
              &quot;type&quot;: &quot;php&quot;,
              &quot;request&quot;: &quot;launch&quot;,
              &quot;runtimeArgs&quot;: [
                  &quot;-dxdebug.mode=debug&quot;,
                  &quot;-dxdebug.start_with_request=yes&quot;,
                  &quot;-S&quot;,
                  &quot;localhost:0&quot;
              ],
              &quot;program&quot;: &quot;&quot;,
              &quot;cwd&quot;: &quot;${workspaceRoot}&quot;,
              &quot;port&quot;: 9003,
              &quot;serverReadyAction&quot;: {
                  &quot;pattern&quot;: &quot;Development Server \\(http://localhost:([0-9]+)\\) started&quot;,
                  &quot;uriFormat&quot;: &quot;http://localhost:%s&quot;,
                  &quot;action&quot;: &quot;openExternally&quot;
              }
          }
      ]
  }
  </code></pre>
  <p>Extra information:
  this is my program and i've put a break point on &quot;$var = &quot;txt1&quot; &quot; line, but it runs directly towards &quot;xdebug_info()&quot;</p>
  <pre><code>&lt;?php
  
  function fprint(string $str):void{
      echo $str;
  }
  
  $var = &quot;txt1&quot;;
  fprint($var);
  
  $var = &quot;txt2&quot;;
  fprint($var);
  
  $var = &quot;txt3&quot;;
  fprint($var);
  // echo $PHP_INI_DIR;
  // echo phpinfo();
  xdebug_info();
  </code></pre>