Remote debugging a node.js docker container not working

 I am writing a node.js app in typescript to run in a docker container.  I would like to use the webstorm debugger to set breakpoints to test the app on my local machine running docker locally.  I created the dockerfile and the docker-compose.yml files.  I am running the docker containers from a docker "Run/Debug Configuration" which calls the docker-compose.yml file.  Additionally, I created a "Attach to Node.js/Chrome" Run/Debug configuration to debug the docker container.  The docker Run/Debug configuration starts up and I can see where it is listening for the debugger.  However, when I start the Attach to Node.js/Chrome Run/Debug Configuration my breakpoints are neven reached.  I am just taken to a screen with a command prompt. 

 

Here are the settings I am currently using:

docker-compose.yml:
version: '2.1'
services:
 mongo:
    container_name: "app_mongo"
    hostname: "mongo"
    tty: true
    image: mongo:latest
    environment:
      - MONGO_DATA_DIR=/data/db
      - MONGO_LOG_DIR=/dev/null
      - MONGO_INITDB_DATABASE=************
      - MONGO_INITDB_ROOT_USERNAME=****************
      - MONGO_INITDB_ROOT_PASSWORD=**************
    volumes:
      - /data/dbDocker:/data/db
    ports:
        - 27017:27017
    command: "mongod --smallfiles --auth"
    networks:
    - main-network
 group:
     container_name: "app_group"
     hostname: "group"
     build:
       context: .
       args:
         ENVIRONMENT: development
         NODE_PORT: 3000
         DEBUG_PORT_NAME: 56745
       dockerfile: group.df.yml
     entrypoint: ["npm", "run", "debug"]
     volumes:
       - ".:/home/deb"
     ports:
       - 3000:3000
       - 56745:56745
     depends_on:
       - "mongo"
     networks:
       - main-network
networks:
  main-network:
    driver: bridge



group.df.yml:
# file: df.base
FROM node:latest

ARG ENVIRONMENT
ARG DEBUG_PORT_NAME
ARG NODE_PORT

ADD package.json /tmp/package.json
RUN cd /tmp && npm install --production && npm install -g nodemon
RUN mkdir -p /home/deb && cp -a /tmp/node_modules /home/deb/ && mkdir -p /home/deb/dist

ADD package.json /home/deb/package.json
ADD .env /home/deb/.env
WORKDIR /home/deb

ENV NODE_ENV=$ENVIRONMENT PORT=$NODE_PORT

EXPOSE $NODE_PORT $DEBUG_PORT_NAME




package.json script section:
"scripts": {
  "debug": "nodemon -L --inspect=56745 dist/Group/app.js"
}

 

Docker "Run/Edit Configuration":

 

"Attach to Node.js/Chrome" - Run/Debug Configuration:

 

Docker log screen:

 

Debug console after running "Attach to Nodejs/Chrome" in debug mode:

I am currently using WebStorm version 2018.1.

I am never reaching my breakpoints.  What do I need to fix for the breakpoints to begin working?

 

 

 

 

0
6 comments

How do you transpile your code? Does debugging work if you create breakpoints in generated .js files? Also, can you debug your app locally (not in container, using Node.js run configuration)?

0
Avatar
Permanently deleted user

I am transpiling using a tsconfig file.  The .js and .map files are added to a dist folder.  I tried to set breakpoints for the .js files in the dist folder and they did not work either.  I have not tried that approach as I also need mongo running as well in a container.

0

What OS are you on? Can you check if the issue persists in 2018.3 EAP (https://www.jetbrains.com/webstorm/nextversion/)?

0
Avatar
Permanently deleted user

I am using mac os x, mojave.  I upgraded to 2018.3 EAP.  The problem still persists.

0

Thanks, recreated; however it doesn't look like WebStorm issue, as I can't attach to node.js using other debuggers as well. To work out the issue, I had to change the npm script as follows:

"debug": "nodemon -L --inspect=0.0.0.0:56745 dist/Group/app.js"

to bind to 0.0.0.0 host - as node binds to localhost by default and thus can't be accessed from outside

3
Avatar
Permanently deleted user

Thanks a million.  That did it.

1

Please sign in to leave a comment.