Sort instructions in a dockerfile by type
Source: R/dockerfile-modifications.R
dfm_sort_by_instruction.RdReorders the instructions in a dockerfile according to Docker best practices
or a custom order specification.
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"))