{"id":18755437,"url":"https://github.com/jonfairbanks/docker-node-init","last_synced_at":"2026-05-15T23:10:26.493Z","repository":{"id":40271515,"uuid":"388955834","full_name":"jonfairbanks/docker-node-init","owner":"jonfairbanks","description":"Comparing methods to launch Node.js applications in a Docker environment","archived":false,"fork":false,"pushed_at":"2022-12-30T16:55:40.000Z","size":2201,"stargazers_count":0,"open_issues_count":13,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-08T11:06:32.546Z","etag":null,"topics":["docker","dockerfile","dockerfiles","node","node-js","nodejs","pm2","tini"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/jonfairbanks/docker-node-init","language":"Mustache","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonfairbanks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-24T00:00:45.000Z","updated_at":"2021-08-22T18:37:46.000Z","dependencies_parsed_at":"2023-01-31T12:01:53.625Z","dependency_job_id":null,"html_url":"https://github.com/jonfairbanks/docker-node-init","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/jonfairbanks/docker-node-init","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonfairbanks%2Fdocker-node-init","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonfairbanks%2Fdocker-node-init/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonfairbanks%2Fdocker-node-init/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonfairbanks%2Fdocker-node-init/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonfairbanks","download_url":"https://codeload.github.com/jonfairbanks/docker-node-init/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonfairbanks%2Fdocker-node-init/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33082921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","dockerfile","dockerfiles","node","node-js","nodejs","pm2","tini"],"created_at":"2024-11-07T17:32:52.645Z","updated_at":"2026-05-15T23:10:26.459Z","avatar_url":"https://github.com/jonfairbanks.png","language":"Mustache","funding_links":[],"categories":[],"sub_categories":[],"readme":"# docker-node-init\n\n![GitHub Workflow Status](\u003chttps://img.shields.io/github/workflow/status/jonfairbanks/docker-node-init/Create%20Release(s)?label=Docker%20Build\u003e)\n![GitHub top language](https://img.shields.io/github/languages/top/jonfairbanks/docker-node-init.svg)\n![Docker Pulls](https://img.shields.io/docker/pulls/jonfairbanks/docker-node-init.svg)\n![GitHub last commit](https://img.shields.io/github/last-commit/jonfairbanks/docker-node-init.svg)\n![Lines of code](https://img.shields.io/tokei/lines/github/jonfairbanks/docker-node-init)\n![License](https://img.shields.io/github/license/jonfairbanks/docker-node-init.svg?style=flat)\n\nPM2 is a very popular application used to launch Node.js (and other scripts) in a production fashion.\n\nAlthough PM2 does a good job of launching process on bare-metal, it is not ideal in a Docker environment.\n\n## What's wrong with PM2 \u0026 Docker?\n\nWhen a Node.js process exits, it exits with a particular process event:\n\n- SIGINT\n- SIGTERM\n- SIGKILL\n\nIf the Node script is started with `npm start` for example, these events may not be properly exposed to the parent process(es) allowing error handling to take place.\n\nSimilar scenarios may take place when using `pm2 start index.js` within a Docker container. If a `SIG*` event is thrown, the event may be swallowed by `npm` or `pm2`.\n\n[PM2 does offer a method for Docker](https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/), however there's a better way. Read on!\n\n## So what should I use instead?\n\n👉 [tini](https://github.com/krallin/tini) 👈\n\nFrom the repo:\n\n\u003e All Tini does is spawn a single child (Tini is meant to be run in a container), and wait for it to exit all the while reaping zombies and performing signal forwarding.\n\n## Example Dockerfiles\n\nIn this repository are a few sample Dockerfiles --\n\n- [Dockerfile](Dockerfile): A barebones Dockerfile which supports exposing a Node.js app; common in online tutorials\n- [Dockerfile-pm2](Dockerfile-pm2): An advanced Dockerfile with environments and security scans, but is using `pm2`\n- [Dockerfile-tini](Dockerfile-tini): A production-ready Dockerfile with environments, security scans and proper `SIG*` handling\n\n## Running with Docker\n\nThree versions of this image are available to test each scenario:\n\nBase Docker image:\n\n```\ndocker run -d -p 8080:8080 --name docker-node-init-base jonfairbanks/docker-node-init:latest --restart=always\n```\n\nPM2 Docker image:\n\n```\ndocker run -d -p 8080:8080 --name docker-node-init-pm2 jonfairbanks/docker-node-init:latest-pm2 --restart=always\n```\n\nTini Docker image:\n\n```\ndocker run -d -p 8080:8080 --name docker-node-init-tini jonfairbanks/docker-node-init:latest-tini --restart=always\n```\n\n## Using the App\n\nTo test how a theoretical Node.js app runs in these scenarios, this app exposes a few endpoints to test with:\n\n- [/](#): Landing page\n- [/sigint](#): Sends the app process a `SIGINT` signal after X seconds\n- [/sigkill](#): Sends the app process a `SIGKILL` signal after X seconds\n- [/sigterm](#): Sends the app process a `SIGTERM` signal after X seconds\n\n## Configuration Options\n\nThe following process.env options are supported:\n\n- `PORT` - Override the application port (Default: 8080)\n- `SECS` - Override seconds before process signals are sent (Default: 2)\n\n## Resources\n\n- [PM2 GitHub](https://github.com/Unitech/pm2)\n- [PM2 Docs](https://pm2.keymetrics.io/docs/usage/quick-start)\n- [Process Signal Events](https://nodejs.org/api/process.html#process_signal_events)\n- [Process Exit Codes](https://nodejs.org/api/process.html#process_process_exit_code)\n- [Tini](https://github.com/krallin/tini)\n- [Node.js \u0026 Docker Best Practices](https://github.com/BretFisher/dockercon19)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonfairbanks%2Fdocker-node-init","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonfairbanks%2Fdocker-node-init","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonfairbanks%2Fdocker-node-init/lists"}