Need help with ONBUILD option

Hello,
I have a problem with my Docker on Windows (through Docker Toolbox). May be someone can help.

My Dockerfile without ONBUILD:

FROM node:5.9.1

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app

CMD [ "npm", "start" ]
EXPOSE 3000

Working ok (docker build -t test . and start it: docker run -it --rm --name testrun test)
But if i change Dockerfile to ONBUILD option:

FROM node:5.9.1

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ONBUILD COPY package.json /usr/src/app/
ONBUILD RUN npm install
ONBUILD COPY . /usr/src/app

CMD [ "npm", "start" ]
EXPOSE 3000

I get an errors:

npm info it worked if it ends with ok
npm info using npm@3.7.3
npm info using node@v5.9.1
npm ERR! Linux 4.1.19-boot2docker
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v5.9.1
npm ERR! npm  v3.7.3
npm ERR! path /usr/src/app/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open

npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.js
on'
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.js
on'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /usr/src/app/npm-debug.log

Whats im doing wrong? (im novice in Docker :stuck_out_tongue:). Maybe I’m wrong use ONBUILD? But like anything not clear there is no.

You only use ONBUILD if the image you are building is going to be used as a base for inheritance.

So, for instance, some of the official Dockerfiles do things like this:

FROM node
ONBUILD COPY /app /app
ONBUILD WORKDIR /app
ONBUILD RUN npm install

Then, if you baked that as image foobar/node:onbuild, a subsequent NodeJS Dockerfile might look as simple as:

FROM foobar/node:onbuild

And your app code would then get automatically added into the image during build, as well as having npm install run automatically.

If you’re just baking your own images for running, and don’t anticipate layering them heavily, don’t worry about ONBUILD.