Goal: run a simple NodeJS application inside a Docker container
Subgoal: give it access to local files.
docker run -it --rm --name example -v "$PWD":/usr/src/app -w /usr/src/app node:5-slim node index.js
current working directory /usr/src/app Hello, World!
Unwrapped command line
run - execute the image right away -i - inherit STDIO and STDOUT from the current shell process -t - execute the command (the command "node index.js" is at the end) --rm - remove existing running image --name example - give the running container user friendly name "example" -v "$PWD":/usr/src/app - mount current directory inside the docker container as a volume, set its path as "/usr/src/app" -w /usr/src/app - set the working directory before running the command node:5-slim - use the "node:5-slim" as the docker base image for our container (small!) node index.js - the command to run inside the new container
- More Docker examples at https://gist.github.com/bahmutov/1003fa86980dda147ff6
- Node Docker images at the docker hub