Adds a VOLUME
instruction to create a mount point with the specified name
and mark it as holding externally mounted volumes.
Details
The VOLUME
instruction creates a mount point and marks it as being externally
mounted. This is useful for:
Persistent data that should survive container restarts
Data you want to share between containers
Data you want to access from the host
Note that the actual binding of host directories happens at runtime using the
-v
flag with docker run
, not during the image build.
See also
dk_template_base()
for a template that sets up common volume patterns &
Official Docker VOLUME
documentation
Other dockerfile instruction functions:
dfi_add()
,
dfi_arg()
,
dfi_cmd()
,
dfi_copy()
,
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_workdir()
Examples
# Create a single volume
df <- dockerfile() |>
dfi_from("rocker/r-ver:4.4.0") |>
dfi_volume("/data")
df
#> FROM rocker/r-ver:4.4.0
#> VOLUME /data
# Create multiple volumes
df <- dockerfile() |>
dfi_from("rocker/r-ver:4.4.0") |>
dfi_volume(c("/data", "/output", "/config"))
df
#> FROM rocker/r-ver:4.4.0
#> VOLUME ["/data","/output","/config"]