Group similar instructions in a dockerfile
Source: R/dockerfile-modifications.R
dfm_group_similar.Rd
Optimizes a dockerfile
by grouping similar consecutive instructions
into single multi-command instructions where appropriate. This can reduce
the number of layers in the final Docker image.
Details
This function primarily targets RUN
instructions, combining them with &&
to create single multi-command instructions. This follows Docker best practices
by reducing the number of layers in the final image. Instructions like FROM
,
WORKDIR
, USER
, ENTRYPOINT
, and CMD
are left as separate instructions.
See also
dfm_sort_by_instruction()
for sorting instructions by type
Other dockerfile modification functions:
dfm_add_line()
,
dfm_move_line()
,
dfm_remove_line()
,
dfm_replace_line()
,
dfm_sort_by_instruction()
Examples
df <- dockerfile() |>
dfi_from("rocker/r-ver:4.4.0") |>
dfi_run("apt-get update") |>
dfi_run("apt-get install -y curl") |>
dfi_run("apt-get clean")
# Group the three RUN instructions into one
df <- dfm_group_similar(df)