Coder Social home page Coder Social logo

alpine-node's Introduction

Minimal Node.js Docker Images

Versions v12.10.0, v10.16.3, v8.16.1, v6.17.1, v4.9.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 and yarn:
    • latest, 12, 12.10, 12.10.0 – 78.8 MB (npm 6.11.3, yarn 1.17.3)
    • 10, 10.16, 10.16.3 – 74.7 MB (npm 6.10.3, yarn 1.17.3)
    • 8, 8.16, 8.16.1 – 66.8 MB (npm 6.10.2, yarn 1.17.3)
  • Full install build with npm:
    • 6, 6.17, 6.17.1 – 49 MB (npm 3.10.10)
    • 4, 4.9, 4.9.1 – 35.2 MB (npm 2.15.12)
    • 0.12, 0.12.18 – 32.4 MB (npm 2.15.12)
    • 0.10, 0.10.48 – 27.8 MB (npm 2.15.12)
  • Slim install with no npm or yarn:
    • slim, slim-12, slim-12.10, slim-12.10.0 – 44.8 MB
    • slim-10, slim-10.16, slim-10.16.3 – 41.3 MB
    • slim-8, slim-8.16, slim-8.16.1 – 36.1 MB
    • slim-6, slim-6.17, slim-6.17.1 – 32.5 MB

Examples

$ docker run --rm mhart/alpine-node:12 node --version
v12.10.0

$ docker run --rm mhart/alpine-node:10 node --version
v10.16.3

$ docker run --rm mhart/alpine-node:12 npm --version
6.11.3

$ docker run --rm mhart/alpine-node:12 yarn --version
1.17.3

$ docker run --rm mhart/alpine-node:8 node --version
v8.16.1

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

$ docker run --rm mhart/alpine-node:slim-10 node --version
v10.16.3

$ docker run --rm mhart/alpine-node:slim-8 node --version
v8.16.1

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

Example Dockerfile for your own Node.js project

Assuming you're doing your npm install or yarn install from your Dockerfile, you'll probably want to add node_modules to your .dockerignore file first, so that it doesn't get sent to the docker daemon.

Here's a typical example using a "full install" image:

FROM mhart/alpine-node:12

WORKDIR /app
COPY . .

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

RUN npm install --prod

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

However, for an even smaller build: from Docker version 17.05 onwards, you can do multi-stage builds – so you can npm ci or yarn install using the full install image, but then create your app using the slim image – this can reduce the size of your final image by ~35MB or so.

FROM mhart/alpine-node:12
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci --prod

# Only copy over the node pieces we need from the above image
FROM mhart/alpine-node:slim-12
WORKDIR /app
COPY --from=0 /app .
COPY . .
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).

If you get an error similar to error loading shared library ld-linux-x86-64.so.2, it may be that you have dependencies relying on libc – you can try to fix this by adding RUN apk add --no-cache libc6-compat or RUN ln -s /lib/libc.musl-x86_64.so.1 /lib/ld-linux-x86-64.so.2 to your Dockerfile.

Inspired by:

alpine-node's People

Contributors

dalisoft avatar jakxz avatar mhart avatar qix- avatar rudijs avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.