title: Docker + Xdebug + VSCode Could not connect to client
body: <p>PHP version: 7.1.20</p>
  
  <p>XDebug version: 2.7.0</p>
  
  <p>I'm using a Docker container on MacOS Mojave.
  On pressing "F5", it shows debug options Pause, Restart, and Stop. But Step Over, Step Into, Step Out are disabled.</p>
  
  <p>I'm kind of learner because I was used to code till 2012-13 on Windows OS. After that year, I am back to coding this month. :) Even after reviewing a lot of posts on Google about how to resolve this issue, I'm not sure how to finally make it work. Please help.</p>
  
  <p>My <code>launch.json</code> file:</p>
  
  <pre><code>{
      "version": "0.2.0",
      "configurations": [
          {
              "name": "Listen for XDebug",
              "type": "php",
              "request": "launch",
              "port": 9001,
              "log": true,
              "pathMappings": {
                  "/var/www/html": "${workspaceFolder}/learn"
              }
          },
          {
              "name": "Launch currently open script",
              "type": "php",
              "request": "launch",
              "program": "${file}",
              "cwd": "${fileDirname}",
              "port": 9001
          }
      ]
  }
  </code></pre>
  
  <p>XDebug <code>php.ini</code> config:</p>
  
  <pre><code>xdebug.remote_host = 172.20.0.1
  xdebug.remote_port = 9001
  xdebug.scream = 1
  xdebug.remote_enable = 1
  xdebug.show_local_vars = 1
  xdebug.remote_autostart = 1
  xdebug.remote_connect_back = 1
  xdebug.remote_log = "/var/www/html/xdebug.log"
  xdebug.idekey = "VSCODE"
  </code></pre>
  
  <p>XDebug logfile (from setting xdebug.remote_log in php.ini):</p>
  
  <pre><code>[12] Log opened at 2019-05-12 10:16:44
  [12] I: Checking remote connect back address.
  [12] I: Checking header 'HTTP_X_FORWARDED_FOR'.
  [12] I: Checking header 'REMOTE_ADDR'.
  [12] I: Remote address found, connecting to 172.20.0.1:9001.
  [12] W: Creating socket for '172.20.0.1:9001', poll success, but error: Operation now in progress (29).
  [12] E: Could not connect to client. :-(
  [12] Log closed at 2019-05-12 10:16:44
  </code></pre>
  
  <p>Debug console:</p>
  
  <pre><code>&lt;- launchResponse
  Response {
    seq: 0,
    type: 'response',
    request_seq: 2,
    command: 'launch',
    success: true }
  </code></pre>
  
  <p>Here's the <code>dockerfile</code>.</p>
  
  <pre><code>FROM php:7.1.20-apache
  
  RUN apt-get -y update --fix-missing
  RUN apt-get upgrade -y
  
  # Install tools &amp; libraries
  RUN apt-get -y install apt-utils nano wget dialog \
      build-essential git curl libcurl3 libcurl3-dev zip
  
  # Install important libraries
  RUN apt-get -y install --fix-missing apt-utils build-essential git curl libcurl3 libcurl3-dev zip \
      libmcrypt-dev libsqlite3-dev libsqlite3-0 mysql-client zlib1g-dev \
      libicu-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev
  
  # Composer
  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  
  # PHP Extensions
  RUN pecl install xdebug-2.7.0 \
      &amp;&amp; docker-php-ext-enable xdebug \
      &amp;&amp; docker-php-ext-install mcrypt \
      &amp;&amp; docker-php-ext-install pdo_mysql \
      &amp;&amp; docker-php-ext-install pdo_sqlite \
      &amp;&amp; docker-php-ext-install mysqli \
      &amp;&amp; docker-php-ext-install curl \
      &amp;&amp; docker-php-ext-install tokenizer \
      &amp;&amp; docker-php-ext-install json \
      &amp;&amp; docker-php-ext-install zip \
      &amp;&amp; docker-php-ext-install -j$(nproc) intl \
      &amp;&amp; docker-php-ext-install mbstring \
      &amp;&amp; docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
      &amp;&amp; docker-php-ext-install -j$(nproc) gd \
      &amp;&amp; pecl install redis \
      &amp;&amp; docker-php-ext-enable redis
  
  # Enable apache modules
  RUN a2enmod rewrite headers
  
  ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
  </code></pre>
  
  <p>Here's the <code>docker-compose.yml</code> file.</p>
  
  <pre><code>version: "3"
  
  services:
    webserver:
      build: 
        context: ./bin/webserver
      container_name: '7.1.x-webserver'
      restart: 'always'
      ports:
        - "80:80"
        - "443:443"
      links: 
        - mysql
      volumes: 
        - ${DOCUMENT_ROOT-./www}:/var/www/html
        - ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
        - ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
        - ${LOG_DIR-./logs/apache2}:/var/log/apache2
    mysql:
      build: ./bin/mysql
      container_name: '5.7-mysql'
      restart: 'always'
      ports:
        - "3306:3306"
      volumes: 
        - ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
        - ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
      environment:
        MYSQL_ROOT_PASSWORD: tiger
    phpmyadmin:
      image: phpmyadmin/phpmyadmin
      container_name: 'sc-phpmyadmin'
      links:
        - mysql
      environment:
        PMA_HOST: mysql
        PMA_PORT: 3306
      ports:
        - '8080:80'
      volumes: 
        - /sessions
    redis:
      container_name: 'sc-redis'
      image: redis:latest
      ports:
        - "6379:6379"
  </code></pre>
  
  <p>Thank you in advance.</p>