How to run one-off command in docker

If you want to just run a command on a docker image without permanently creating a container, run

docker run -it --rm [image] [command]

for example

docker run -it --rm node:latest npm --version

By using --rm we tell docker to immediately remove the container once the command has finished.