This repository contains Dockerfiles for ficusio/node-alpine image, which is ~33MB in virtual size.
This image contains Node.js v5.7 and NPM v3.7. It is based on Alpine linux, which, despite
being a very lightweight distribution, provides apk package manager, allowing easy
installation of many pre-built packages.
This is an extended version of node-alpine, with added ONBUILD triggers (similar to and
inspired by google/nodejs-runtime image). These triggers execute on each build of a derived
image, and perform two tasks:
- Copy everything from the directory containing
Dockerfileto the/appdirectory inside the container, but skipnode_modulesdirectory and all files/dirs listed in the.dockerignorefile; - Install NPM-managed dependencies; reuse Docker image cache if dependencies have not changed since previous build.
This allows Dockerfiles of derived images to contain less boilerplate instructions:
FROM ficusio/node-alpine:5-onbuild
EXPOSE 8080
# This will be performed automatically:
# WORKDIR /app
# COPY . /app
# npm install --production
# CMD ["node", "index.js"]The image's Dockerfile contains comments that explain all steps performed by these triggers. There is also an example application which uses this image as a base.
There is an issue with Node.js/Docker combination
which prevents Node from exiting on INT and TERM signals when it runs inside a Docker
container. It can be worked around by manually handling these signals in the app, which is
a useful thing anyway:
exitOnSignal('SIGINT');
exitOnSignal('SIGTERM');
function exitOnSignal(signal) {
process.on(signal, function() {
console.log('\ncaught ' + signal + ', exiting');
// perform all required cleanup
process.exit(1);
});
}PRs and issues are welcome!
- Edit base/Dockerfile and change
NODEJS_VERSION,NODEJS_SHA256andNPM_VERSIONvariables. - If you've changed major or patch version of Node, edit .tags file to reflect
this change. Then, update
FROMinstruction in onbuild/Dockerfile to match the new$major.$minortag.
-
To build new version, run
./make build. It will build newbaseandonbuildvariations and tag them as$image:$variation-build, where$imagecomes from the .image file. -
To tag images built in the previous step, run
./make tag. It will tag each$image:$variation-buildimage as$image:$tag-$variation, for each$taglisted in the .tags file. The exception to this rule isbasevariation, which gets tagged as$image:$tag. -
To push images tagged in step 2, run
./make push. You'll need push access to the$imageDocker Hub repository.
To perform all these steps at once, run ./make all.