@@ -20,30 +20,37 @@ See: http://nodejs.org
20
20
21
21
# How to use this image
22
22
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
25
24
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
31
29
```
32
30
33
- Then simply run:
31
+ You can then build and run the Docker image :
34
32
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
39
36
```
40
37
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
44
39
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
47
54
```
48
55
49
56
# Image Variants
@@ -68,6 +75,23 @@ This image makes building derivative images easier. For most use cases, creating
68
75
a ` Dockerfile ` in the base of your project directory with the line `FROM
69
76
node: onbuild ` will be enough to create a stand-alone image for your project.
70
77
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
+
71
95
## ` node:slim `
72
96
73
97
This image does not contain the common packages contained in the default tag and
@@ -85,9 +109,13 @@ Node.js Docker project.
85
109
86
110
# Supported Docker versions
87
111
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.
89
115
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.
91
119
92
120
# People
93
121
0 commit comments