Skip to content

Instantly share code, notes, and snippets.

@ericorruption
Created January 12, 2022 13:29
Show Gist options
  • Save ericorruption/db9776d6b24669456170a1db0a901689 to your computer and use it in GitHub Desktop.
Save ericorruption/db9776d6b24669456170a1db0a901689 to your computer and use it in GitHub Desktop.
Simplest node development environment with docker
services:
node:
image: node:16
user: "node"
command: "npm start"
working_dir: /app
volumes:
- ./:/app
ports:
- 3000:3000
@ericorruption
Copy link
Author

ericorruption commented Jan 12, 2022

This assumes that you have a package.json file with an npm script called start.
It also assumes that a server runs on npm start on port 3000, and this port is attached to your localhost port of same number.
(A good example of this setup is create react app.)

Usage is generally like this:

  • install dependencies before running: docker compose run node npm install
  • run development environment: docker compose up
  • install new dependencies: docker compose run node npm install [package name]
  • clean up docker instances created with compose run and compose up: docker compose down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment