Adds a COPY
instruction to copy files or directories from the build context
to the container's filesystem.
Details
The COPY
instruction copies new files or directories from src
and adds them to the filesystem of the container at the path dest
.
When used with the from
parameter, it can copy files from previous
build stages in multi-stage builds.
See also
dfi_add()
for similar functionality with additional features (like URL support),
dfi_workdir()
for setting the working directory, &
Official Docker COPY
documentation
Other dockerfile instruction functions:
dfi_add()
,
dfi_arg()
,
dfi_cmd()
,
dfi_entrypoint()
,
dfi_env()
,
dfi_expose()
,
dfi_from()
,
dfi_healthcheck()
,
dfi_label()
,
dfi_maintainer()
,
dfi_onbuild()
,
dfi_run()
,
dfi_shell()
,
dfi_stopsignal()
,
dfi_user()
,
dfi_volume()
,
dfi_workdir()
Examples
# Copy a single file
df <- dockerfile() |>
dfi_from("rocker/r-ver:4.4.0") |>
dfi_copy("script.R", "/app/script.R")
# Copy from a previous build stage
df <- dockerfile() |>
dfi_from("rocker/r-ver:4.4.0", as = "build") |>
dfi_run("R -e \"install.packages('renv')\"") |>
dfi_from("rocker/r-ver:4.4.0", as = "final") |>
dfi_copy("/usr/local/lib/R/site-library/renv",
"/usr/local/lib/R/site-library/renv",
from = "build")