Goal: run a simple NodeJS application inside a Docker container

February 14, 2016 ยท View on GitHub

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

output:

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