Skip to contents

Reorders the instructions in a dockerfile according to Docker best practices or a custom order specification.

Usage

dfm_sort_by_instruction(dockerfile, order = NULL)

Arguments

dockerfile

A dockerfile object

order

Custom order for instructions (optional)

Value

A new dockerfile object with instructions sorted by type

Details

The default order follows Docker best practices, with instructions that change less frequently appearing first (e.g., FROM, ARG, LABEL), and instructions that change more frequently appearing later (e.g., COPY, RUN). This improves caching and build performance.

See also

dfm_group_similar() for grouping similar instructions

Other dockerfile modification functions: dfm_add_line(), dfm_group_similar(), dfm_move_line(), dfm_remove_line(), dfm_replace_line()

Examples

df <- dockerfile() |>
  dfi_cmd("R --no-save") |>
  dfi_run("apt-get update") |>
  dfi_from("rocker/r-ver:4.4.0")
  
# Sort according to best practices (FROM first, etc.)
df <- dfm_sort_by_instruction(df)

# Use a custom order
df <- dfm_sort_by_instruction(df, 
  order = c("FROM", "RUN", "WORKDIR", "CMD"))