How to shrink size of Docker image with NodeJs How to shrink size of Docker image with NodeJs docker docker

How to shrink size of Docker image with NodeJs


You can certainly use my alpine-ng image if you like.

You can also check out the dockerfile, if you want to try and modify it in some way.

I regret to inform you that even based on alpine, it is still 610MB. An improvement to be sure, but there is no getting around the fact that the angular compiler is grossly huge.


For production, you do not need to distribute an image with Node.js, NPM dependencies, etc. You simply need an image that can be used to start a data volume container that provides the compiled sources, release source maps and other assets, effectively no more than what you would redistributed with a package via NPM, that you can attach to your webserver.

So, for your CI host, you can pick one of the node:alpine distributions and copy the sources and install the dependencies therein, then you can re-use the image for running containers that test the builds until you finally run a container that performs a production compilation, which you can name.

docker run --name=compile-${RELEASE} ci-${RELEASE} npm run production

After you have finished compiling the sources within a container, run a container that has the volumes from the compilation container attached and copy the sources to a volume on the container and push that to your Docker upstream:

docker run --name=release-${RELEASE} --volumes-from=compile-${RELEASE} -v /srv/public busybox cp -R /myapp/dist /srv/publicdocker commit release-${RELEASE} release-${RELEASE} myapp:${RELEASE}


Try FROM mhart/alpine-node:base-6 maybe it will work.