Public Repository

Last pushed: a day ago
Short Description
Minimal Node.js built on Alpine Linux
Full Description

Supported tags and Dockerfile links

Minimal Node.js Docker Images

Versions v8.2.1, v6.11.1, v4.8.4, v0.12.18 and v0.10.48 –
built on Alpine Linux.

All versions use the one mhart/alpine-node repository,
but each version aligns with the following tags (ie, mhart/alpine-node:<tag>). The sizes are for the
unpacked images as reported by Docker – compressed sizes are about 1/3 of these:

  • Full install built with npm and yarn:
    • latest, 8, 8.2, 8.2.1 – 63.3 MB (npm 5.3.0, yarn 0.27.5)
  • Full install build with npm:
    • 6, 6.11, 6.11.1 – 48.7 MB (npm 3.10.10)
    • 4, 4.8, 4.8.4 – 35.2 MB (npm 2.15.12)
    • 0.12, 0.12.18 – 33.36 MB (npm 2.15.11)
    • 0.10, 0.10.48 – 28.16 MB (npm 2.15.11)
  • Base install with node built as a static binary with no npm or yarn:
    • base, base-8, base-8.2, base-8.2.1 – 43.4 MB
    • base-6, base-6.11, base-6.11.1 – 37.2 MB
    • base-4, base-4.8, base-4.8.4 – 26.6 MB
    • base-0.12, base-0.12.18 – 24.72 MB
    • base-0.10, base-0.10.48 – 18.22 MB

Major io.js versions are tagged too.


$ docker run mhart/alpine-node node --version

$ docker run mhart/alpine-node npm --version

$ docker run mhart/alpine-node yarn --version

$ docker run mhart/alpine-node:6 node --version

$ docker run mhart/alpine-node:base node --version

$ docker run mhart/alpine-node:base-0.10 node --version

Example Dockerfile for your own Node.js project

If you don't have any native dependencies, ie only depend on pure-JS npm
modules, then my suggestion is to run npm install locally before running
docker build (and make sure node_modules isn't in your .dockerignore) –
then you don't need an npm install step in your Dockerfile and you don't need
npm installed in your Docker image – so you can use one of the smaller
base* images.

FROM mhart/alpine-node:base-6
# FROM mhart/alpine-node:6

ADD . .

# If you have native dependencies, you'll need extra tools
# RUN apk add --no-cache make gcc g++ python

# If you need npm, don't use a base tag
# RUN npm install

CMD ["node", "index.js"]


As Alpine Linux uses musl, you may run into some issues with environments
expecting glibc-like behavior – especially if you try to use binaries compiled
with glibc. You should recompile these binaries to use musl (compiling on
Alpine is probably the easiest way to do this).

Inspired by:

Docker Pull Command

Comments (14)
4 months ago

Does this run node as root or a special user? If so, what is that user please?

4 months ago

Very good production image. Small and got all the Node goodness.

9 months ago

Excellent work. You are a life saver. Thank you :-)

a year ago

Excellent image, shrank my image from 376MB (official node image based) to 22MB. Great work

a year ago

Love this image. Has anyone gotten Facebook's watchman to work with this Linux distro?

a year ago

Excellent! Thank you! The official images are huge. My app is sitting in a 43MB image, with the official slim image, it would be at least 5 times bigger.

a year ago

Hi Mickael,

Thank you for your reply. Using your image as a base is what I end up doing but I wanted to experiment with the DockerHub build automated process too.

However, I would like to build the image 'from scratch' for build-speed and image-size sake: Alpine-based images take a long time to build because it has to download & compile everything, then remove/uninstall the packages required only for the build of other libraries. Therefore, I would like to group all the apk add and apk del commands in one RUN clause instead of repeating the installation-then-removal of make gcc g++ binutils-gold packages for example.

Anyway, it seems that you manually pushed your images to docker hub, didn't you? Did you try automated builds from your GitHub repo?

Have a nice day!

a year ago

@lucsorel – why don't you just my image as a base (ie, FROM mhart/alpine-node:4), and then add whatever extra things you need after that?

a year ago

@lmvalenzuela – sorry, only just saw this now – of course it's ok!

a year ago

Hi Michael,

I am trying to create a ZeroMQ-powered image for NodeJS based on your 4.3.1 Dockerfile and it works perfectly on my computer (see the Dockerfile below). However, when I trigger an automated build in Docker hub, it fails in the NodeJS installation phase.

The error is at the end of build log but I don't really want you to have a thorough look at it. I am mainly wondering;

  • if you came up with similar issues while building your images on Docker hub or not?
  • if you pushed these images from your computer to Docker hub or if you used automated builds?

Thank you any way for the great work! Have a nice day.


PS: The Dockerfile which ran ok locally, but failed as an automated build in Docker hub:

FROM alpine:3.3
## Inspired by


RUN apk add --no-cache curl make gcc g++ binutils-gold python linux-headers paxctl libgcc libstdc++ && \
  curl -sSL${NODE_VERSION}/node-${NODE_VERSION}.tar.gz | tar -xz && \
  cd /node-${NODE_VERSION} && \
  ./configure --prefix=/usr && \
  make -j$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
  make install && \
  paxctl -cm /usr/bin/node && \
  cd / && \
  if [ -x /usr/bin/npm ]; then \
    npm install -g npm@${NPM_VERSION} && \
    find /usr/lib/node_modules/npm -name test -o -name .bin -type d | xargs rm -rf; \
  fi && \
  apk del curl make gcc g++ binutils-gold python linux-headers paxctl ${DEL_PKGS} && \
  rm -rf /etc/ssl /node-${NODE_VERSION} \
    /usr/share/man /tmp/* /var/cache/apk/* /root/.npm /root/.node-gyp \
    /usr/lib/node_modules/npm/man /usr/lib/node_modules/npm/doc /usr/lib/node_modules/npm/html

# installs ZeroMQ libraries and dependencies for the node-gyp binder, run while npm-installing your app
RUN apk add --no-cache make gcc g++ python zeromq zeromq-dev