在Docker中运行的实时调试节点应用程序

时间:2018-08-10 03:05:40

标签: docker docker-compose

我有在React上运行的应用程序,该应用程序在Docker上运行。我正在寻找一种调试方法。我正在使用Visual Studio Code。这是我的Docker文件和Docker-compose文件

FROM node:boron


ARG build_env

RUN mkdir /usr/share/unicode && cd /usr/share/unicode && wget ftp://ftp.unicode.org/Public/UNIDATA/UnicodeData.txt

COPY package.json /tmp/package.json

RUN cd /tmp && npm install

COPY ./shim/RelayDefaultNetworkLayer.js /tmp/node_modules/react-relay/lib/RelayDefaultNetworkLayer.js
COPY ./shim/buildRQL.js /tmp/node_modules/react-relay/lib/buildRQL.js

RUN mkdir -p /var/www && cp -a /tmp/node_modules /var/www/

WORKDIR /var/www

COPY . ./

RUN if [ "$build_env" != "development" ]; then npm run build-webpack && npm run gulp; fi

EXPOSE 8080

CMD ["npm", "run", "--debug=5858 prod"]

我的docker-compose文件看起来像

version: '2'

services:
  nginx:
    container_name: nginx
    image: openroad/nginx
    build:
      context: nginx
    ports:
      - "80:80"
    volumes:
      - ./nginx/nginx.development.conf:/etc/nginx/nginx.conf
    networks:
      - orion-network

  graphql:
    container_name: graphql
    image: openroad/graphql
    build:
      context: integration_api
    volumes:
      - ./integration_api:/var/www
    environment:
      - NODE_ENV=development
    command: npm run dev
    working_dir: /var/www
    networks:
      orion-network:
        ipv4_address: 172.16.238.10

  pegasus:
    container_name: pegasus
    image: openroad/pegasus
    build:
      context: pegasus
      args:
        build_env: development
    expose:
      - "3000"
    volumes:
      - ./pegasus:/var/www/public
    environment:
      - NODE_ENV=development
    command: npm run dev
    working_dir: /var/www/public
    extra_hosts:
      - "local.pegasus.com:192.168.99.100"
    networks:
      orion-network:
        ipv4_address: 172.16.238.11

  frontend:
    container_name: orion-frontend
    image: openroad/orion-frontend
    build:
      context: orion-frontend
      args:
        build_env: development
    expose:
      - "3000"
    ports:
      - "5858:5858"
    volumes:
      - ./orion-frontend:/var/www/public
    environment:
      - NODE_ENV=development
    command: npm run --debug=5858 dev
    working_dir: /var/www/public
    networks:
      orion-network:
        ipv4_address: 172.16.238.12

  admin:
      container_name: orion-admin
      image: openroad/orion-admin
      build:
        context: orion-admin
        args:
          build_env: development
      expose:
        - "3000"
      volumes:
        - ./orion-admin:/var/www/
      environment:
        - NODE_ENV=development
      command: npm run dev
      working_dir: /var/www/
      networks:
        orion-network:
          ipv4_address: 172.16.238.13

  uploads:
    container_name: orion-uploads
    image: openroad/orion-uploads
    build:
      context: orion-uploads
    volumes:
      - ./orion-uploads:/var/www/
    working_dir: /var/www/
    networks:
      orion-network:
        ipv4_address: 172.16.238.14

  dashboard:
    container_name: orion-dashboard
    image: openroad/orion-dashboard
    build:
      context: orion-dashboard
      args:
        build_env: development
    volumes:
      - ./orion-dashboard/src:/var/www/src
      - ./orion-dashboard/package.json:/var/www/package.json
      - ./orion-dashboard/webpack.config.babel.js:/var/www/webpack.config.babel.js
      - ./orion-dashboard/node_modules:/var/www/node_modules
      - ./orion-dashboard/data/babelRelayPlugin.js:/var/www/data/babelRelayPlugin.js
    working_dir: /var/www
    environment:
      - NODE_ENV=development
      - GRAPHQLURL=http://172.16.238.10:8080/graphql
      - PORT=8080
    command: npm run dev
    networks:
      orion-network:
        ipv4_address: 172.16.238.15

networks:
  orion-network:
    driver: bridge
    driver_opts:
      com.docker.network.bridge.enable_ip_masquerade: "true"
    ipam:
      driver: default
      config:
      - subnet: 172.16.238.0/24
        gateway: 172.16.238.1

我希望能够调试在Orion前端容器下运行的应用程序。我尝试了各种选择,但都没有成功。我已经尝试过https://codefresh.io/docker-tutorial/debug_node_in_docker/https://blog.docker.com/2016/07/live-debugging-docker/

1 个答案:

答案 0 :(得分:0)

对于npm run的命令语法,我可能是错的(在npm docs中找不到此命令),但是您可能需要将--debug=5858prod参数分开,像这样:

CMD ["npm", "run", "--debug=5858", "prod"]