Public Repository

Last pushed: 7 days ago
Short Description
Minimal Node.js built on Alpine Linux
Full Description

Supported tags and Dockerfile links

Minimal Node.js Docker Images

Versions v7.7.4, v6.10.1, v4.8.1, 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:
    • latest, 7, 7.7, 7.7.4 – 54.3 MB (npm 4.4.1)
    • 6, 6.10, 6.10.1 – 49.3 MB (npm 3.10.10)
    • 4, 4.8, 4.8.1 – 36.1 MB (npm 2.15.11)
    • 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:
    • base, base-7, base-7.7, base-7.7.4 – 43.5 MB
    • base-6, base-6.10, base-6.10.1 – 37.8 MB
    • base-4, base-4.8, base-4.8.1 – 27.2 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.

Examples

$ docker run mhart/alpine-node node --version
v7.7.4

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

$ docker run mhart/alpine-node:6 node --version
v6.10.1

$ docker run mhart/alpine-node:base node --version
v7.7.4

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

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

WORKDIR /src
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

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

Caveats

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
Owner
mhart

Comments (13)
miroslawmajka
12 days ago

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

raymondmutagahywa
5 months ago

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

pavelpichrt
8 months ago

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

ksnyde
9 months ago

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

taqenniwa
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.

lucsorel
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!

mhart
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?

mhart
a year ago

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

lucsorel
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.

Luc

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

FROM alpine:3.3
## Inspired by https://github.com/mhart/alpine-node

ENV NODE_VERSION=v4.3.1 NPM_VERSION=2
# ENV NODE_VERSION=v5.6.0 NPM_VERSION=3

RUN apk add --no-cache curl make gcc g++ binutils-gold python linux-headers paxctl libgcc libstdc++ && \
  curl -sSL https://nodejs.org/dist/${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
lmvalenzuela
a year ago

@mhart Michael: I work in a digital agency in México City. We're starting a new blog to share our thoughts with the developer community, and in my first article I would like to use your image to explain my opinion about docker containers. I would like to know if it's ok with you to use your work for this. Regards
Luis M. Valenzuela