VOLUME , , . , node_modules. COPY package.json
, COPY .
. Dockerfile.
FROM node:6.3
RUN mkdir -p /var/www/app
WORKDIR /var/www/app
COPY . /var/www/app
RUN npm install
, .
docker-compose build
, Dockerfile, .
$ tree
.
βββ app
β βββ Dockerfile
β βββ package.json
βββ docker-compose.yml
1 directory, 3 files
$ cat docker-compose.yml
version: "2"
services:
app:
build: ./app
ports:
- "3000"
command: node ./bin/www
$ cat app/Dockerfile
FROM node:6.3
RUN mkdir -p /var/www/app
WORKDIR /var/www/app
COPY . /var/www/app
RUN npm install
$ cat app/package.json
{
"name": "app",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"body-parser": "^1.13.3",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"express": "~4.13.1",
"helmet": "^3.0.0",
"jade": "~1.11.0",
"redis": "^2.6.2",
"serve-favicon": "~2.3.0"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-complexity": "^0.3.2",
"gulp-concat": "^2.6.1",
"gulp-cssnano": "^2.1.2",
"gulp-less": "^3.3.0",
"gulp-uglify": "^1.5.4",
"gulp-watch": "^4.3.11",
"strip-debug": "^1.1.1",
"util": "^0.10.3"
}
}
.
$ docker-compose build
Building app
Step 1/5 : FROM node:6.3
6.3: Pulling from library/node
357ea8c3d80b: Pull complete
...
646e6da4bf07: Pull complete
Digest: sha256:cde2bd38dbfec5e6e2981ec7a05056c734148fcd4bff088e143f11b2bafe3b64
Status: Downloaded newer image for node:6.3
---> 0d9089853221
Step 2/5 : RUN mkdir -p /var/www/app
---> Running in 018dd9b28c57
---> 18cc43628367
Removing intermediate container 018dd9b28c57
Step 3/5 : WORKDIR /var/www/app
---> b8fa2b1a2624
Removing intermediate container ba1ad506cab2
Step 4/5 : COPY . /var/www/app
---> 3f37c76acdc4
Step 5/5 : RUN npm install
---> Running in dd87c26c2546
npm info it worked if it ends with ok
npm info using npm@3.10.3
npm info using node@v6.3.1
npm info attempt registry request try #1 at 11:39:41 AM
npm http request GET https://registry.npmjs.org/body-parser
...
npm info lifecycle util@0.10.3~postinstall: util@0.10.3
npm info lifecycle app@0.0.0~preinstall: app@0.0.0
npm info linkStuff app@0.0.0
npm info lifecycle app@0.0.0~install: app@0.0.0
npm info lifecycle app@0.0.0~postinstall: app@0.0.0
npm info lifecycle app@0.0.0~prepublish: app@0.0.0
app@0.0.0 /var/www/app
+-- body-parser@1.18.2
| +-- bytes@3.0.0
...
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.1.2
npm info ok
---> d1bfc665f54c
Removing intermediate container dd87c26c2546
Successfully built d1bfc665f54c
Successfully tagged so47173020_app:latest
Dockerfile, , docker-compose up app
, node_modules.
version: "2"
services:
app:
build: ./app
ports:
- "3000"
command: ls -la node_modules
docker-compose up app
:
Creating so47173020_app_1 ...
Creating so47173020_app_1 ... done
Attaching to so47173020_app_1
app_1 | total 2004
app_1 | drwxr-xr-x 497 root root 20480 Nov 10 11:40 .
app_1 | drwxr-xr-x 1 root root 4096 Nov 10 11:40 ..
app_1 | drwxr-xr-x 2 root root 4096 Nov 10 11:40 .bin
app_1 | drwxr-xr-x 2 root root 4096 Nov 10 11:40 accepts
app_1 | drwxr-xr-x 4 root root 4096 Nov 10 11:40 accord
...
app_1 | drwxr-xr-x 3 root root 4096 Nov 10 11:40 x-xss-protection
app_1 | drwxr-xr-x 2 root root 4096 Nov 10 11:40 xtend
app_1 | drwxr-xr-x 3 root root 4096 Nov 10 11:40 yargs
so47173020_app_1 exited with code 0