Skip to content

Instantly share code, notes, and snippets.

@khalidx
Created December 2, 2021 03:35
Show Gist options
  • Save khalidx/2e71c96babeb8b8d2a1b27596fc87181 to your computer and use it in GitHub Desktop.
Save khalidx/2e71c96babeb8b8d2a1b27596fc87181 to your computer and use it in GitHub Desktop.
Quickly execute a node script in a fresh docker container

Read more about using the official Node.js docker image.

running a file

Quickly execute a node script in a fresh docker container using the command below.

The current directory where the command is run will be mounted into the container as a volume.

docker run -it --rm --name my-running-script \
-v "$PWD":/usr/src/app -w /usr/src/app \
node:14 \
node your-daemon-or-script.js

evaluating code

docker run -it --rm --name my-running-script \
-v "$PWD":/usr/src/app -w /usr/src/app \
node:14 \
node -e "console.log('hello world')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment