1

Estou tendo problemas ao tentar debugar uma aplicação que está sendo executada em um container usando o Xdebug. Ao que parece, o Xdebug não se conecta com a minha IDE, mesmo estando escutando a porta 9001. Estou usando o Linux, por isso não consigo utilizar o host.docker.internal na diretiva xdebug.remote_host do xdebug.ini, mesmo tentando utilizar uma solução alternativa no meu dockerfile: RUN ip -4 route list match 0/0 | awk '{print $3 " host.docker.internal"}' >> /etc/hosts.

Dockerfile:

FROM ubuntu:14.04

ARG DEBIAN_FRONTEND=noninteractive

USER root

#####################################
# Non-Root User:
#####################################

# Add a non-root user to prevent files being created with root permissions on host machine.
ARG PUID=1000
ARG PGID=1000

ENV PUID ${PUID}
ENV PGID ${PGID}

RUN groupadd -g ${PGID} ubuntu && \
    useradd -u ${PUID} -g ubuntu -m ubuntu && \
    apt-get update -yqq

# RUN apt-get install -y software-properties-common && \
    # add-apt-repository -y ppa:ondrej/php

# PHP 5 AND EXTENSIONS INSTALL
RUN apt-get update && \
    apt-get install -y \
        php5-cli \
        php5-common \
        php5-curl \
        php5-json \
        # php5-xml \
        # php5-mbstring \
        php5-mcrypt \
        php5-mysql \
        # php5-sqlite3 \
        # php5-zip \
        # php5-bcmath \
        php5-gd \
        php5-dev \
        pkg-config \
        libcurl4-openssl-dev \
        libedit-dev \
        libssl-dev \
        libxml2-dev \
        xz-utils \
        libsqlite3-dev \
        git \
        curl \
        vim \
        nano \
    && apt-get clean

# APACHE2 AND APACHE_PHP 5 INSTALL with rewrite enabled
RUN apt-get update -q && apt-get install -yqq --force-yes \
        apache2 \
        libapache2-mod-php5 \
    && apt-get clean \
    && a2enmod rewrite

# ENABLE MCRYPT
RUN php5enmod mcrypt

# Source the bash
RUN . ~/.bashrc

# ADD DEFAULT VHOST
COPY ./docker/000-default.conf /etc/apache2/sites-available/000-default.conf

#####################################
# xDebug:
#####################################
USER root

RUN apt-get install -y --force-yes php5-xdebug && \
    sed -i 's/^;//g' /etc/php5/cli/conf.d/20-xdebug.ini && \
    echo "alias phpunit='php -dzend_extension=xdebug.so /var/www/vendor/bin/phpunit'" >> ~/.bashrc 

RUN ip -4 route list match 0/0 | awk '{print $3 " host.docker.internal"}' >> /etc/hosts

# ADD for REMOTE debugging
COPY ./docker/xdebug.ini /etc/php5/cli/conf.d/xdebug.ini

#####################################
# NODE INSTALL:
#####################################
USER ubuntu

# Check if NVM needs to be installed
ARG NODE_VERSION=6.9
ENV NVM_DIR /home/ubuntu/.nvm

RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash && \
        . $NVM_DIR/nvm.sh && \
        nvm install ${NODE_VERSION} && \
        nvm use ${NODE_VERSION} && \
        nvm alias ${NODE_VERSION} 

# Wouldn't execute when added to the RUN statement in the above block
# Source NVM when loading bash since ~/.profile isn't loaded on non-login shell
RUN echo "" >> ~/.bashrc && \
    echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc && \
    echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm' >> ~/.bashrc 

# Add NVM binaries to root's .bashrc
USER root

RUN echo "" >> ~/.bashrc && \
    echo 'export NVM_DIR="/home/ubuntu/.nvm"' >> ~/.bashrc && \
    echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm' >> ~/.bashrc 

#####################################
# TESSERACT INSTALL:
#####################################

RUN apt-get install tesseract-ocr -y

# Clean up
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

# Set default work directory
WORKDIR /var/www/html

xdebug.ini:

; Defaults
xdebug.default_enable=1
xdebug.remote_enable=1
xdebug.remote_port=9001
xdebug.remote_host=host.docker.internal
xdebug.remote_handler=dbgp

; The Linux way
xdebug.remote_connect_back=1

; idekey value is specific to Visual Studio Code
xdebug.idekey=VSCODE

; Optional: Set to true to always auto-start xdebug
xdebug.remote_autostart=true

docker-compose.yml:

version: '3.1'
services:
  smarty-center:
    build:
      dockerfile: ./docker/Dockerfile
      context: .
    ports:
      - "80:80"
    links:
      - mysql56:mysql
    volumes:
      - .:/var/www/html
    container_name: app
    networks:
      - homologacao-network
    depends_on:
      - mysql56
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    environment:
      - MYSQL_ROOT_PASSWORD=nopass
    ports:
      - "8000:80"
    links:
      - mysql56:db
    container_name: phpmyadmin
    networks:
      - homologacao-network
    depends_on:
      - mysql56
  mysql56:
    image: mysql:5.6
    environment:
      - MYSQL_ROOT_PASSWORD=nopass
    volumes:
      - ./docker/mysql:/var/lib/mysql
    container_name: mysql56
    networks:
      - homologacao-network
    ports:
      - "3306:3306"
networks:
  homologacao-network:
    driver: bridge

lauch.json

{
    // 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
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Xdebug for Project smarty center",
            "type": "php",
            "request": "launch",
            "port": 9001,
            "log": true,
            "pathMappings": {
                "/var/www/html": "${workspaceRoot}"
            }
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 9001
        }
    ]
}

0

Pesquise outras perguntas com a tag .