Skip to main content

Base Image

A base image is the image named in a Dockerfile FROM instruction that your image builds on. It supplies the operating system files, package manager, and often the language runtime, and it largely decides image size and security exposure.

What a base image provides

Every Dockerfile starts with FROM. The image named there becomes the bottom layers of your image: the userland (Debian, Alpine, or none), a package manager, and sometimes a runtime such as Node.js or Python. Everything you add sits on top, so the base image sets your starting size, your inherited CVEs, and how easy debugging will be.

Common choices for a Node.js service

Base image Typical use Trade-off
node:20 Build stages Large, includes compilers
node:20-slim Runtime with glibc Smaller, glibc compatible
node:20-alpine Small runtime musl libc can break native modules
distroless/nodejs20 Hardened runtime No shell, harder to debug
scratch Static binaries Empty, needs static linking

Sizes change between releases, so measure your own image with docker images instead of trusting fixed numbers.

Pin the base image

Dockerfile
# Floating tag: can change under you
FROM node:20-alpine
# Pinned version: predictable
FROM node:20.18.0-alpine3.20
# Tag plus digest: readable and immutable
FROM node:20.18.0-alpine3.20@sha256:<digest-from-your-registry>
Bash
# Find the digest of an image you already pulled
docker inspect node:20-alpine --format '{{index .RepoDigests 0}}'
# Scan before you ship
trivy image node:20-alpine

Use Renovate or Dependabot to open pull requests when a pinned base image has a new version, so patches arrive through review.

Common Mistake

Shipping the full node:20 or python:3.12 image to production. Build tools and extra packages add size and CVEs the running app never uses.

Tip

Use a full image only in a build stage and copy the output into a slim or distroless final stage. See multi-stage build.

Frequently Asked Questions

Is Alpine always the best base image?

No. Alpine is small, but it uses musl instead of glibc, which can break prebuilt native wheels or binaries and cause runtime errors. If your dependencies include native code, a -slim Debian variant is often the safer small choice.

Why pin a base image by digest?

Tags are mutable, so the same FROM line can pull different bytes next week. A digest identifies exact content, which makes builds reproducible, and automated update PRs let you take security patches deliberately.

Does a smaller base image automatically mean a more secure one?

It usually reduces attack surface because fewer packages means fewer CVEs and no shell for attackers. Security also depends on patch frequency and how you run the container, such as non-root user and dropped capabilities.

Found a mistake, an outdated step or a broken link?