BretFisher / node-docker-good-defaults

sample node app for Docker examples
MIT License
2.35k stars 489 forks source link
docker docker-compose dockerfile nodejs nodemon npm vscode

Node.js + Docker for Showing Good Defaults in Using Node.js with Docker

Lint Code Base Docker Build

This tries to be a "good defaults" example of starting to use Node.js in Docker for local development and shipping to production with basic bells, whistles, and best practices. Issues/PR welcome.

Note I have more advanced examples of Node.js Dockerfiles and Compose files in my DockerCon 2022 talk and repository. I also have more about everything Docker and Node.js in my 8 hour video course Docker for Node.js.

Also Note, I have other resources on Docker and Kubernetes here.

Local Development Features

Production-minded Features

Assumptions

Getting Started

If this was your Node.js app, to start local development you would:

If you wanted to add a package while docker-compose was running your app:

To execute the unit-tests, you would:

Ways to improve security

Run Node.js as Non-Root User

As mentioned in the official docker Node.js image docs, Docker runs the image as root. This can pose a potential security issue.

As a security best practice, it is recommended for Node.js apps to listen on non-privileged ports as mentioned here.

Other Resources