@@ -20,30 +20,37 @@ See: http://nodejs.org
2020
2121# How to use this image
2222
23- If you want to distribute your application on the docker registry, create a
24- ` Dockerfile ` in the root of application directory:
23+ ## Create a ` Dockerfile ` in your Node.js app project
2524
26- ``` Dockerfile
27- FROM node:onbuild
28-
29- # Expose the ports that your app uses. For example:
30- EXPOSE 8080
25+ ``` dockerfile
26+ FROM node:4-onbuild
27+ # replace this with your application's default port
28+ EXPOSE 8888
3129```
3230
33- Then simply run:
31+ You can then build and run the Docker image :
3432
35- ```
36- $ docker build -t node-app .
37- ...
38- $ docker run --rm -it node-app
33+ ``` console
34+ $ docker build -t my-nodejs-app .
35+ $ docker run -it --rm --name my-running-app my-nodejs-app
3936```
4037
41- To run a single script, you can mount it in a volume under ` /usr/src/app ` . From
42- the root of your application directory (assuming your script is named
43- ` index.js ` ):
38+ ### Notes
4439
45- ```
46- $ docker run -v ${PWD}:/usr/src/app -w /usr/src/app -it --rm node node index.js
40+ The image assumes that your application has a file named
41+ [ ` package.json ` ] ( https://docs.npmjs.com/files/package.json ) listing its
42+ dependencies and defining its [ start
43+ script] ( https://docs.npmjs.com/misc/scripts#default-values ) .
44+
45+ ## Run a single Node.js script
46+
47+ For many simple, single file projects, you may find it inconvenient to write a
48+ complete ` Dockerfile ` . In such cases, you can run a Node.js script by using the
49+ Node.js Docker image directly:
50+
51+ ``` console
52+ $ docker run -it --rm --name my-running-script -v " $PWD " :/usr/src/app -w
53+ /usr/src/app node:4 node your-daemon-or-script.js
4754```
4855
4956# Image Variants
@@ -68,6 +75,23 @@ This image makes building derivative images easier. For most use cases, creating
6875a ` Dockerfile ` in the base of your project directory with the line `FROM
6976node: onbuild ` will be enough to create a stand-alone image for your project.
7077
78+ While the ` onbuild ` variant is really useful for "getting off the ground
79+ running" (zero to Dockerized in a short period of time), it's not recommended
80+ for long-term usage within a project due to the lack of control over * when* the
81+ ` ONBUILD ` triggers fire (see also
82+ [ ` docker/docker#5714 ` ] ( https://github.com/docker/docker/issues/5714 ) ,
83+ [ ` docker/docker#8240 ` ] ( https://github.com/docker/docker/issues/8240 ) ,
84+ [ ` docker/docker#11917 ` ] ( https://github.com/docker/docker/issues/11917 ) ).
85+
86+ Once you've got a handle on how your project functions within Docker, you'll
87+ probably want to adjust your ` Dockerfile ` to inherit from a non-` onbuild `
88+ variant and copy the commands from the ` onbuild ` variant ` Dockerfile ` (moving
89+ the ` ONBUILD ` lines to the end and removing the ` ONBUILD ` keywords) into your
90+ own file so that you have tighter control over them and more transparency for
91+ yourself and others looking at your ` Dockerfile ` as to what it does. This also
92+ makes it easier to add additional requirements as time goes on (such as
93+ installing more packages before performing the previously-` ONBUILD ` steps).
94+
7195## ` node:slim `
7296
7397This image does not contain the common packages contained in the default tag and
@@ -85,9 +109,13 @@ Node.js Docker project.
85109
86110# Supported Docker versions
87111
88- This image is officially supported on Docker version 1.8.3.
112+ This image is officially supported on Docker version 1.9.1.
113+
114+ Support for older versions (down to 1.6) is provided on a best-effort basis.
89115
90- Support for older versions (down to 1.0) is provided on a best-effort basis.
116+ Please see [ the Docker installation
117+ documentation] ( https://docs.docker.com/installation/ ) for details on how to
118+ upgrade your Docker daemon.
91119
92120# People
93121
0 commit comments