|
|
3 år sedan | |
|---|---|---|
| .. | ||
| src | 3 år sedan | |
| test | 5 år sedan | |
| Dockerfile | 5 år sedan | |
| LICENSE | 6 år sedan | |
| README.md | 3 år sedan | |
| healthcheck.js | 5 år sedan | |
| package-lock.json | 3 år sedan | |
| package.json | 3 år sedan | |
This tries to be a "good defaults" example of using Node.js in Docker for local development and shipping to production with all the bells, whistles, and best practices. Issues/PR welcome.
node_modules outside app root in container so local development won't run into a problem of bind-mounting over it with local source code. This means it will run npm install once on container build and you don't need to run npm on host or on each docker run. It will re-run on build if you change package.json.docker-compose up for single-line build and run of local development server.--inspect by default in docker compose..vscode directory has the goods, thanks to @JPLemelin.COPY in package.json and run npm install before COPY in your source code. This saves big on build time and keep container lean.dce node npm install --save <package name>HEALTHCHECK with /healthz route to help Docker know if your container is running properly (example always returns 200, but you get the idea).NODE_ENV=production in Dockerfile and overrides to development in docker compose for local dev.NODE_ENV use means dev dependencies won't be installed in container by default. Using docker compose will build with them by default.node index.js rather then npm for allowing graceful shutdown of node. npm doesn't pass SIGTERM/SIGINT properly (you can't ctrl-c when running docker run in foreground). To get node index.js to graceful exit, extra signal-catching code is needed. The Dockerfile and index.js document the options and links to known issues.docker-compose for local development only (docker-compose was never intended to be a production deployment tool anyway).compose.yaml is not meant for docker stack deploy in Docker Swarm, it's meant for happy local development. Use docker-stack.yml for Swarm.If this was your Node.js app, to start local development you would:
docker-compose up is all you need. It will:NODE_ENV=development).nodemon to restart node on file change in host pwd.up.docker-compose build works for manually building.docker-compose down to cleanup after your done dev'ing.If you wanted to add a package while docker compose was running your app:
docker-compose exec node npm install --save <package name>--save will add it to the package.json for next docker-compose buildTo execute the unit-tests, you would:
docker-compose exec node npm test, It will:npm test in the container node.Docker Test (Attach 9230 --inspect), It will:
MIT License,
Copyright (c) 2015-2018 Bret Fisher
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.