← All recipes
Open source

Change Docker FROM

Recipe IDorg.openrewrite.docker.ChangeFrom
Artifactorg.openrewrite:rewrite-docker

Change the base image in a Dockerfile FROM instruction. Each * in an old* glob is a positional capture; $N in the paired new* substitutes capture N. $0 substitutes the full original value; \$ is a literal dollar.

Single recipeApache 2.0

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.docker.ChangeFrom --recipe-option "oldImageName=ubuntu"

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite:rewrite-docker:8.88.0

Options

NameTypeDescription
oldImageNamerequiredStringGlob pattern to match image names (without tag/digest).
e.g. ubuntu
oldTagStringOnly match images with tags matching this glob pattern. If null, matches any tag or no tag.
e.g. 20.*
oldDigestStringOnly match images with digests matching this glob pattern. If null, matches any digest or no digest. If empty (""), matches only images that have no digest, which is useful for skipping digest-pinned FROMs so deliberate pins are left untouched.
e.g. sha256:*
oldPlatformStringOnly change images with this platform. If null, matches any platform.
e.g. linux/amd64
newImageNameStringThe new image name. If null, preserves the existing name.
e.g. ubuntu
newTagStringThe new tag. If null, preserves the existing tag. If empty, removes the tag.
e.g. 22.04
newDigestStringThe new digest. If null, preserves the existing digest. If empty, removes the digest.
e.g. sha256:abc123...
newPlatformStringThe new platform. If null, preserves the existing platform. If empty, removes the platform flag.
e.g. linux/arm64

Data tables

Structured output this recipe can produce.

  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats