This repository contains Dockerfile of Node.js w/ Bower & Grunt runtime for Docker's automated build published to the public Docker Hub Registry.
This image is a base image for easily running Node.js application.
It can automatically bundle a Node.js
application with its dependencies and set the default command with no additional Dockerfile instructions.
This project heavily borrowed code from Google's google/nodejs-runtime Docker image.
-
Install Docker.
-
Download automated build from public Docker Hub Registry:
docker pull dockerfile/nodejs-bower-grunt-runtime
(alternatively, you can build an image from Dockerfile:
docker build -t="dockerfile/nodejs-bower-grunt-runtime" github.com/dockerfile/nodejs-bower-grunt-runtime
)
This image assumes that your application:
- has a file named package.json listing its dependencies.
- has a file named bower.json listing its dependencies.
- has a file named Gruntfile.js registering
build
task. - has a file named
server.js
as the entrypoint script or define in package.json the attribute:"scripts": {"start": "node <entrypoint_script_js>"}
- listens on port
8080
When building your application docker image, ONBUILD
triggers install NPM module dependencies of your application using npm install
.
- Step 1: Create a Dockerfile in your
Node.js
application directory with the following content:
FROM dockerfile/nodejs-bower-grunt-runtime
- Step 2: Build your container image by running the following command in your application directory:
docker build -t="app" .
- Step 3: Run application by mapping port
8080
:
APP=$(docker run -d -p 8080 app)
PORT=$(docker port $APP 8080 | awk -F: '{print $2}')
echo "Open http://localhost:$PORT/"