Skip to content

Instantly share code, notes, and snippets.

@glennschler
Last active January 23, 2018 09:12
Show Gist options
  • Save glennschler/9fe9e070afb11b94612d to your computer and use it in GitHub Desktop.
Save glennschler/9fe9e070afb11b94612d to your computer and use it in GitHub Desktop.
node-inspector debug node app running in docker container
docker build -t nodedebug .
docker build -t iojsdebug --file=iojs/Dockerfile .

docker run -it --name nodedebug -d -p 8080:8080 nodedebug

# example with different js (js must have been in the path when built)
docker run -it --name iojsdebug -d -p 8080:8080 iojsdebug ./test/test1.js $APPARG1 CMDARG2
docker run -it --name iojsdebug2 -d -p 8081:8080 iojsdebug ./test/test1.js $APPARG1 CMDARG2

# start up two then examine the port that was auto forwarded
docker run -it --name iojsdebug2 -d -P iojsdebug
docker run -it --name iojsdebug -d -P iojsdebug
docker ps

# list the IP address of docker machine. For example, if machine is named "docker"
# To get the IP to navigate to in blink tools browser (chrome)
docker-machine ip docker

Then navigate chrome or webstorm to

Some additonal commands

# list containers
docker ps -l

docker stop nodedebug
docker rm nodedebug

# bash into the running container
docker exec -i -t iodebug bash

# remove any recently created images
docker rmi $(docker images | awk '$5 ~ /minutes/ {print $3}')
FROM node:onbuild
ADD ./package.json /tmp/package.json
RUN npm install -g node-inspector
RUN cd /tmp && npm install
RUN mkdir -p /opt/app/node
RUN if [ -d /tmp/node_modules ] ; then cp -a /tmp/node_modules /opt/app/node; fi
WORKDIR /opt/app/node
ADD . /opt/app/node
RUN cd /opt/app/node
EXPOSE 8080
ENTRYPOINT ["node-debug"]
# These are default parameters which can be overriden at run time
CMD ["--web-host", "0.0.0.0", "--cli", "true", "./index.js"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment