Skip to contents

Moves a line from one position to another in a dockerfile.

Usage

dfm_move_line(dockerfile, from, to)

Arguments

dockerfile

A dockerfile object

from

Source line number

to

Target position

Value

An updated dockerfile object with the line moved to the new position

Details

This function allows for reorganizing instructions in a Dockerfile by moving lines to different positions. It's useful for correcting the order of instructions without having to recreate the entire Dockerfile.

Note that moving certain instructions to incompatible positions can make the Dockerfile invalid (e.g., moving a FROM instruction after a RUN). Consider using dfm_sort_by_instruction() to follow Docker best practices.

See also

dfm_add_line() for adding a line, dfm_remove_line() for removing a line, & dfm_sort_by_instruction() for sorting instructions by type

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

Examples

df <- dockerfile() |>
  dfi_from("rocker/r-ver:4.4.0") |>
  dfi_workdir("/app") |>
  dfi_run("apt-get update") |>
  dfi_copy(".", "/app/")

df
#> FROM rocker/r-ver:4.4.0
#> WORKDIR /app
#> RUN apt-get update
#> COPY . /app/ 
  
# Move the RUN instruction to be after COPY
df <- dfm_move_line(df, 3, 4)
df
#> FROM rocker/r-ver:4.4.0
#> WORKDIR /app
#> COPY . /app/
#> RUN apt-get update