This repository was archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
This repository was archived by the owner on Jul 11, 2023. It is now read-only.
Docker Configuration Changes #142
Copy link
Copy link
Open
Description
From #118:
Goal:
- Nothing needed by new dev other than
git clonethendocker-compose up.
Compose configuration:
- Update to compose 3.1 format to support secrets and swarm stacks in prod. (Update Docker to v3.3 #143)
[ ] Implement secrets in compose (compose file 3.1 format).Looks like we're going Heroku which won't use compose files in prod.- Remove
.envto reduce developer complexity and prevent env var bleeding into unnecessary containers (e.g, node keys in db container). Move those vars to compose file. - default
docker-compose.ymlis designed for local dev ease-of-use. Any other overrides can be added in other files for CI or Prod.
Dockerfile/Docker Hub:
- always pin versions in Dockerfile when possible (node stable)
- store node image in
code4hrorg and keep it up to date with latest node stable (it rebuilds when upstream node repo changes)
Tooling:
- file watcher that's fast at restarting node when needed locally
- remove proxy from being used for local dev. It's only needed for prod and some limited proxy testing by ops on occasion.
(Pulled the following from the Node.js Good Defaults README):
Local Development Features:
- Dev as close to prod as you can. docker-compose builds a local development image that is just like production image except for the below dev-only features needed in image. Goal is to have dev env be as close to test and prod as possible while still giving all the nice tools to make you a happy dev.
- Prevent needing node/npm on host. Installs
node_modulesoutside 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 runnpm installonce 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 changepackage.json. - One line startup. Uses
docker-compose upfor single-line build and run of local development server. - Edit locally while code runs in container. docker-compose uses proper bind-mounts of host source code into container so you can edit locally while running code in Linux container.
- Use nodemon in container. docker-compose uses nodemon for development for auto-restarting node in container when you change files on host.
- Enable debug from host to container. opens the legacy debug port 5858 and new inspect port 9229 for using host-based debugging like chrome tools or VS Code. Nodemon enables
--inspectby default in docker-compose, but you can change to--debugfor < 6.3 debugging. - Provides VSCode debug config. for Visual Studio Code fans,
.vscodehas a config for both--debugand--inspectnode options. - Small image and quick re-builds.
COPYinpackage.jsonand runnpm install && npm cache cleanbeforeCOPYin your source code. This saves big on build time and keep container lean.
Production-minded Features:
- Use Docker build-in healthchecks. uses Dockerfile
HEALTHCHECKwith/healthzroute to help Docker know if your container is running properly (example always returns 200, but you get the idea). - Proper NODE_ENV use. Defaults to
NODE_ENV=productionin Dockerfile and overrides todevelopmentin docker-compose for local dev. - Don't add dev dependencies into production image. Proper
NODE_ENVuse means dev dependencies won't be installed in container by default. Using docker-compose will build with them by default. - Enables proper SIGTERM/SIGINT for graceful exit. Defaults to
node index.jsrather then npm for allowing graceful shutdown of node. npm doesn't pass SIGTERM/SIGINT properly (you can't ctrl-c when runningdocker runin foreground). To getnode index.jsto graceful exit, extra signal-catching code is needed. TheDockerfileandindex.jsdocument the options and links to known issues.