Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between node images for Docker and when to use which?

Hello guys sorry I am new to docker so bear with me. I am learning to use docker for building, running and shipping some apps but still don't know the difference between Node images (ex. latest, alpine..) I've read somewhere that alpine is a small Linux distribution (in terms of size) but still don't know the difference between all these images and especially when to use which?

Dockerfile:

enter image description here

like image 744
Ismail Chbiki Avatar asked Sep 08 '25 05:09

Ismail Chbiki


1 Answers

All of the standard Docker Hub images have a corresponding Docker Hub page; for Node it's https://hub.docker.com/_/node. There's a section entitled "Image Variants" on that page that lists out the major options.

Debian/Ubuntu/Alpine. Most Docker images are built on top of one of these base Linux distributions. Debian and Ubuntu are very similar and in fact are closely related; if you see something labeled "bullseye", "buster", or "stretch", these are the names of specific Debian major releases. Alpine has a reputation for being very small, but with that tininess comes some potential low-level C library issues. I'd recommend the Debian-based option unless you really need the tens of megabytes of space savings.

"Slim" images. The node image has a "slim" variant. The default image mentions that it's built on top of a buildpack-deps image, but that base image is not small (~300 MB). That image includes a full C toolchain and many development headers. Some npm install commands could need this, but you don't want it in your final image. Prefer the "slim" option if it's a choice.

Version tags. The top of the Docker Hub page has a bewildering list of tags. If you look at these, each line has several names; as of this writing, node:16, node:16.14, node:16.14.0, node:lts, node:16-buster, and several other things are all actually the same image. One thing to note is that only "current" versions get any sort of updates at all; if Node 16.14.0 is the current version then no node:16.13 package will ever be rebuilt. I'd suggest picking a specific major version and using a "long-term support" version if it's an option, but not specifying a minor or patch version.

Combining all of those together, my default would be something like

FROM node:16-slim # Debian-based
like image 136
David Maze Avatar answered Sep 10 '25 08:09

David Maze