简体   繁体   English

我可以将 Xdebug 存储在单独的 docker 容器中吗?

[英]Can I store Xdebug inside separate docker container?

I am new to Docker and docker-compose. I have met the point that it's better to put each process to separate containers.我是Docker和docker-compose的新手。我遇到了一点,最好将每个进程放在单独的容器中。 So I put stuff like Composer, npm, artisan, Redis, pma to separate containers.所以我把像 Composer, npm, artisan, Redis, pma 这样的东西放到不同的容器中。

Now I am trying to integrate Xdebug and use it in PhpStorm.现在我正在尝试集成 Xdebug 并在 PhpStorm 中使用它。 Can't understand how to put it separately.无法理解如何将它分开。 And should I actually?我真的应该吗? And do I understand this paradigm right?我理解这个范例吗?

My docker-compose.xml:我的 docker-compose.xml:

version: '3'

networks:
  laravel:

services:
  nginx:
    image: nginx:stable-alpine
    container_name: nginx
    ports:
      - "8088:80"
    volumes:
      - ../src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql
    networks:
      - laravel

  mysql:
    image: mysql:5.7.22
    container_name: mysql
    restart: unless-stopped
    tty: true
    ports:
      - "3306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: test
      MYSQL_USER: root
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: secret
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks:
      - laravel

  php:
    build:
      context: ./php
      dockerfile: Dockerfile
    container_name: php
    volumes:
      - ../src:/var/www/html
    ports:
      - "9000:9000"
    networks:
      - laravel

  pma:
    image: phpmyadmin/phpmyadmin
    container_name: pma
    environment:
      PMA_HOST: mysql
      PMA_PORT: "3306"
    ports:
      - "7760:80"
    links:
      - mysql
    networks:
      - laravel

  redis:
    image: redis:5-alpine
    container_name: redis
    command: redis-server --bind 0.0.0.0 --requirepass secret@123
    networks:
      - laravel
    ports:
      - "6379:6379"
    restart: unless-stopped
    volumes:
      - ./redis:/data

  queues:
    build:
      context: ./queues
      dockerfile: Dockerfile
    container_name: queues
    command: php /var/www/html/artisan queue:listen
    depends_on:
      - nginx
      - redis
    volumes:
      - ../src:/var/www/html
    networks:
      - laravel

  laravel-echo-server:
    image: oanhnn/laravel-echo-server
    container_name: laravel-echo-server
    depends_on:
      - redis
    environment:
      LARAVEL_ECHO_SERVER_AUTH_HOST: http://localhost:8088
      LARAVEL_ECHO_SERVER_DEBUG: 'true'
      LARAVEL_ECHO_SERVER_DB: redis
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_PREFIX: laravel_
      REDIS_PASSWORD: secret@123
      REDIS_DB: 0
    networks:
      - laravel
    ports:
      - 6001:6001
    restart: unless-stopped

  artisan:
    build:
      context: ./php
      dockerfile: Dockerfile
    container_name: artisan
    volumes:
      - ../src:/var/www/html
    depends_on:
      - php
      - mysql
    working_dir: /var/www/html
    entrypoint: ['php', '/var/www/html/artisan']
    networks:
      - laravel

  xdebug:
    build:
      context: ./xDebug
      dockerfile: Dockerfile
    container_name: xdebug
    depends_on:
      - php
    working_dir: /var/www/html
    networks:
      - laravel

  composer:
    image: composer:latest
    container_name: composer
    volumes:
      - ../src:/var/www/html
    working_dir: /var/www/html
    networks:
      - laravel

  npm:
    image: node:latest
    container_name: npm
    volumes:
      - ../src:/var/www/html
    working_dir: /var/www/html
    entrypoint: ['npm']
    networks:
      - laravel

  git:
    image: alpine/git
    container_name: git
    volumes:
      - ../src:/var/www/html
    working_dir: /var/www/html
    networks:
      - laravel

No, you should include Xdebug inside the container you're trying to debug (be it Laravel or any other PHP application).不,您应该在您尝试调试的容器中包含 Xdebug(无论是 Laravel 还是任何其他 PHP 应用程序)。

You shouldn't actually break down each and every part of every component from your application into different containers, but instead set containers following a separation of concerns concept inside your application, usually based on their role inside the application architecture.实际上,您不应该将应用程序中每个组件的每个部分分解到不同的容器中,而是根据应用程序中的关注点分离概念设置容器,通常基于它们在应用程序体系结构中的角色。

Example (each bullet is a container):示例(每个项目符号都是一个容器):

  • Application server with HTTP routes for APIs具有 HTTP API 路由的应用程序服务器
  • Artisan queue工匠队列
  • Static content server with Angular/React/etc (this one could also be bundled with the first) Static 带有 Angular/React/etc 的内容服务器(这个也可以与第一个捆绑在一起)
  • Redis database Redis 数据库
  • MySQL database MySQL 数据库

And with each one, install everything you need to run/debug/profile the application inside (ie mysql+mysql-cli, or PHP+composer+Xdebug).对于每一个,安装运行/调试/分析应用程序所需的一切(即 mysql+mysql-cli,或 PHP+composer+Xdebug)。

You can read more in this answer .您可以在这个答案中阅读更多内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM