Run different node versions with docker 17 Nov 2016

With docker it’s easy to run a script with different node version.

Either the script is piped into docker. This requires the --interactive flag.

$ echo "console.log(process.version)" | docker run --interactive node:4-alpine node
v4.6.2
$ echo "console.log(process.version)" | docker run --interactive node:6-alpine node
v6.9.1
$ echo "console.log(process.version)" | docker run --interactive node:7-alpine node
v7.1.0

Or if the script is more complex and requires dependencies the folder can be mounted as a volumne.

$ echo 'console.log(process.version)' > script.js; docker run  --volume $(pwd):/volume node:7-alpine node /volume/script.js
v7.1.0

This results in no dependencies besides docker installed on the system.