├── Dockerfile ├── LICENSE └── README.md /Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # Node.js runtime Dockerfile 3 | # 4 | # https://github.com/dockerfile/nodejs-runtime 5 | # 6 | 7 | # Pull base image. 8 | FROM dockerfile/nodejs 9 | 10 | # Set instructions on build. 11 | ONBUILD ADD package.json /app/ 12 | ONBUILD RUN npm install 13 | ONBUILD ADD . /app 14 | 15 | # Define working directory. 16 | WORKDIR /app 17 | 18 | # Define default command. 19 | CMD ["npm", "start"] 20 | 21 | # Expose ports. 22 | EXPOSE 8080 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Dockerfile Project 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Node.js runtime Dockerfile 2 | 3 | 4 | This repository contains **Dockerfile** of [Node.js](http://nodejs.org/) runtime for [Docker](https://www.docker.com/)'s [automated build](https://registry.hub.docker.com/u/dockerfile/nodejs-runtime/) published to the public [Docker Hub Registry](https://registry.hub.docker.com/). 5 | 6 | This image is a base image for easily running [Node.js](http://nodejs.org/) application. 7 | 8 | It can automatically bundle a `Node.js` application with its dependencies and set the default command with no additional Dockerfile instructions. 9 | 10 | This project heavily borrowed code from Google's [google/nodejs-runtime](https://registry.hub.docker.com/u/google/nodejs-runtime/) Docker image. 11 | 12 | 13 | ### Base Docker Image 14 | 15 | * [dockerfile/nodejs](http://dockerfile.github.io/#/nodejs) 16 | 17 | 18 | ### Installation 19 | 20 | 1. Install [Docker](https://www.docker.com/). 21 | 22 | 2. Download [automated build](https://registry.hub.docker.com/u/dockerfile/nodejs-runtime/) from public [Docker Hub Registry](https://registry.hub.docker.com/): `docker pull dockerfile/nodejs-runtime` 23 | 24 | (alternatively, you can build an image from Dockerfile: `docker build -t="dockerfile/nodejs-runtime" github.com/dockerfile/nodejs-runtime`) 25 | 26 | 27 | ### Usage 28 | 29 | This image assumes that your application: 30 | 31 | * has a file named [package.json](https://www.npmjs.org/doc/json.html) listing its dependencies. 32 | * has a file named `server.js` as the entrypoint script or define in package.json the attribute: `"scripts": {"start": "node "}` 33 | * listens on port `8080` 34 | 35 | When building your application docker image, `ONBUILD` triggers install NPM module dependencies of your application using `npm install`. 36 | 37 | * **Step 1**: Create a Dockerfile in your `Node.js` application directory with the following content: 38 | 39 | ```dockerfile 40 | FROM dockerfile/nodejs-runtime 41 | ``` 42 | 43 | * **Step 2**: Build your container image by running the following command in your application directory: 44 | 45 | ```sh 46 | docker build -t="app" . 47 | ``` 48 | 49 | * **Step 3**: Run application by mapping port `8080`: 50 | 51 | ```sh 52 | APP=$(docker run -d -p 8080 app) 53 | PORT=$(docker port $APP 8080 | awk -F: '{print $2}') 54 | echo "Open http://localhost:$PORT/" 55 | ``` 56 | --------------------------------------------------------------------------------