Notes on hot reload debug in node containers - Arthyon/microservice-poc GitHub Wiki
It is currently not possible to have both hot reloading and debugging in node containers.
This section describes encountered challenges and attempted workarounds.
PM2
Can run ts-files with watch directly. The problem is that it is using ts-node@latest under the hood, and a breaking change in ts-node makes it unable to read node args (i.e. --inspect=0.0.0.0:9229). This means that we cannot run ts directly AND debug at the same time.
An attempted workaround is to let tsc watch ts-files and build, and pm2 watch build output directory for reloading, running these concurrently in the container using a package.json-task. This either forces pm2 to create new debug ports (which does not play well with how we expose ports out of docker) or forces it to attempt to attach to the same port. The latter fails because port is still in use. We cannot kill the port using SIGTERM because the signal does not propagate to our app when pm2 is not allowed to run a js-file directly.
Issue touching upon breaking change in ts-node: https://github.com/Unitech/pm2/issues/3512
Nodemon
Works good for debugging (will reuse inspector port even in container), but cannot restart when running in containers. It seems like the signals aren't propagated correctly to the app (specifically SIGUSR2), so the port is never released before restart. Have tried package kill-port, but I still get EADDRINUSE for specific port. nodemon: https://github.com/remy/nodemon Nodemon-events: https://medium.com/netscape/nodemon-events-run-tasks-at-server-start-restart-crash-exit-93a34c54dfd8
people using kill port: https://github.com/remy/nodemon/issues/1050 A bit about using ts-node && nodemon: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000386099-How-to-debug-ts-node-via-Attach-to-Node-js-Chrome-
debugging TS in docker, recipe from MS: https://github.com/Microsoft/vscode-recipes/tree/master/Docker-TypeScript
blog about developing with nodemon in docker: https://medium.com/lucjuggery/docker-in-development-with-nodemon-d500366e74df
Tini, should be able to use this to forward signals, didn't work for me: https://github.com/krallin/tini