| Title: | Easy Dockerfile Creation from R |
| Version: | 1.0.0 |
| Description: | Build a Dockerfile straight from your R session. 'dockerfiler' allows you to create step by step a Dockerfile, and provide convenient tools to wrap R code inside this Dockerfile. |
| License: | MIT + file LICENSE |
| URL: | https://thinkr-open.github.io/dockerfiler/, https://github.com/ThinkR-open/dockerfiler |
| BugReports: | https://github.com/ThinkR-open/dockerfiler/issues |
| Imports: | attempt (≥ 0.3.1), cli (≥ 2.3.0), desc (≥ 1.2.0), fs (≥ 1.5.0), glue (≥ 1.4.2), jsonlite (≥ 1.7.2), memoise, pak (≥ 0.6.0), pkgbuild (≥ 1.2.0), purrr, R6 (≥ 2.5.0), remotes (≥ 2.2.0), usethis (≥ 2.0.1), utils |
| Suggests: | knitr (≥ 1.31), renv, rmarkdown (≥ 2.6), testthat (≥ 3.0.0), withr |
| VignetteBuilder: | knitr |
| Config/fusen/version: | 0.6.0 |
| Config/testthat/edition: | 3 |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| NeedsCompilation: | no |
| Packaged: | 2026-05-13 09:16:49 UTC; PC |
| Author: | Colin Fay |
| Maintainer: | Colin Fay <contact@colinfay.me> |
| Repository: | CRAN |
| Date/Publication: | 2026-05-14 06:30:02 UTC |
dockerfiler: Easy Dockerfile Creation from R
Description
Build a Dockerfile straight from your R session. 'dockerfiler' allows you to create step by step a Dockerfile, and provide convenient tools to wrap R code inside this Dockerfile.
Author(s)
Maintainer: Colin Fay contact@colinfay.me (ORCID)
Authors:
Vincent Guyader vincent@thinkr.fr (ORCID)
Josiah Parry josiah.parry@gmail.com (ORCID)
Sébastien Rochette sebastien@thinkr.fr (ORCID)
See Also
Useful links:
Report bugs at https://github.com/ThinkR-open/dockerfiler/issues
A Dockerfile template
Description
A Dockerfile template
A Dockerfile template
Public fields
DockerfileThe dockerfile content.
Methods
Public methods
Method new()
Create a new Dockerfile object.
Usage
Dockerfile$new(FROM = "rocker/r-base", AS = NULL)
Arguments
FROMThe base image. Default
"rocker/r-base". (Note: the high-level generatorsdock_from_desc()anddock_from_renv()use a different default,rocker/r-vertagged with your R version.)ASOptional build-stage name (
FROM ... AS <name>). DefaultNULL(noAS).
Returns
A Dockerfile object.
Method RUN()
Add a RUN command.
Usage
Dockerfile$RUN(cmd)
Arguments
cmdThe command to add.
Returns
the Dockerfile object, invisibly.
Method ADD()
Add a ADD command.
Usage
Dockerfile$ADD(from, to, force = TRUE)
Arguments
fromThe source file.
toThe destination file.
forceIf TRUE, overwrite the destination file.
Returns
the Dockerfile object, invisibly.
Method COPY()
Add a COPY command.
Usage
Dockerfile$COPY(from, to, stage = NULL, force = TRUE)
Arguments
fromThe source file.
toThe destination file.
stageOptional. Name of the build stage (e.g.,
"builder") to copy files from. This corresponds to the--from=part in a Dockerfile COPY instruction (e.g.,COPY --from=builder /source /dest). IfNULL, the--from=argument is omitted.forceIf TRUE, overwrite the destination file.
Returns
the Dockerfile object, invisibly.
Method WORKDIR()
Add a WORKDIR command.
Usage
Dockerfile$WORKDIR(where)
Arguments
whereThe working directory.
Returns
the Dockerfile object, invisibly.
Method EXPOSE()
Add a EXPOSE command.
Usage
Dockerfile$EXPOSE(port)
Arguments
portThe port to expose.
Returns
the Dockerfile object, invisibly.
Method VOLUME()
Add a VOLUME command.
Usage
Dockerfile$VOLUME(volume)
Arguments
volumeThe volume to add.
Returns
the Dockerfile object, invisibly.
Method CMD()
Add a CMD command.
Usage
Dockerfile$CMD(cmd)
Arguments
cmdThe command to add.
Returns
the Dockerfile object, invisibly.
Method LABEL()
Add a LABEL command.
Usage
Dockerfile$LABEL(key, value)
Arguments
key, valueThe key and value of the label.
Returns
the Dockerfile object, invisibly.
Method ENV()
Add an ENV command.
Usage
Dockerfile$ENV(key, value)
Arguments
key, valueThe key and value of the environment variable.
Returns
the Dockerfile object, invisibly.
Method ENTRYPOINT()
Add a ENTRYPOINT command.
Usage
Dockerfile$ENTRYPOINT(cmd)
Arguments
cmdThe command to add.
Returns
the Dockerfile object, invisibly.
Method USER()
Add a USER command.
Usage
Dockerfile$USER(user)
Arguments
userThe user to add.
Returns
the Dockerfile object, invisibly.
Method ARG()
Add a ARG command.
Usage
Dockerfile$ARG(arg, ahead = FALSE, default = NULL)
Arguments
argThe argument to add.
aheadIf TRUE, add the argument at the beginning of the Dockerfile.
defaultOptional default value. When not
NULL, the directive becomesARG <arg>=<default>. Requiresargto be just the name (no embedded=); supplying both an inlined=inargand a non-NULLdefaulterrors.
Returns
the Dockerfile object, invisibly.
Method ONBUILD()
Add a ONBUILD command.
Usage
Dockerfile$ONBUILD(cmd)
Arguments
cmdThe command to add.
Returns
the Dockerfile object, invisibly.
Method STOPSIGNAL()
Add a STOPSIGNAL command.
Usage
Dockerfile$STOPSIGNAL(signal)
Arguments
signalThe signal to add.
Returns
the Dockerfile object, invisibly.
Method HEALTHCHECK()
Add a HEALTHCHECK command.
Usage
Dockerfile$HEALTHCHECK(check)
Arguments
checkThe check to add.
Returns
the Dockerfile object, invisibly.
Method SHELL()
Add a SHELL command.
Usage
Dockerfile$SHELL(shell)
Arguments
shellThe shell to add.
Returns
the Dockerfile object, invisibly.
Method MAINTAINER()
Add a MAINTAINER command.
Usage
Dockerfile$MAINTAINER(name, email)
Arguments
name, emailThe name and email of the maintainer.
Returns
the Dockerfile object, invisibly.
Method custom()
Add a custom command.
Usage
Dockerfile$custom(base, cmd)
Arguments
base, cmdThe base and command to add.
Returns
the Dockerfile object, invisibly.
Method COMMENT()
Add a comment.
Usage
Dockerfile$COMMENT(comment)
Arguments
commentThe comment to add.
Returns
the Dockerfile object, invisibly.
Method print()
Print the Dockerfile.
Usage
Dockerfile$print()
Returns
used for side effect
Method write()
Write the Dockerfile to a file.
Usage
Dockerfile$write(as = "Dockerfile", append = FALSE)
Arguments
asThe file to write to.
appendboolean, if TRUE append to file.
Returns
used for side effect
Method switch_cmd()
Switch commands.
Usage
Dockerfile$switch_cmd(a, b)
Arguments
a, bThe commands to switch.
Returns
the Dockerfile object, invisibly.
Method remove_cmd()
Remove a command.
Usage
Dockerfile$remove_cmd(where)
Arguments
whereThe commands to remove.
Returns
the Dockerfile object, invisibly.
Method add_after()
Add a command after another.
Usage
Dockerfile$add_after(cmd, after)
Arguments
cmdThe command to add.
afterWhere to add the cmd
Returns
the Dockerfile object, invisibly.
Method clone()
The objects of this class are cloneable with this method.
Usage
Dockerfile$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
my_dock <- Dockerfile$new()
Compact Sysreqs
Description
Compact Sysreqs
Usage
compact_sysreqs(
pkg_installs,
update_cmd = "apt-get update -y",
install_cmd = "apt-get install -y",
clean_cmd = "rm -rf /var/lib/apt/lists/*"
)
Arguments
pkg_installs |
pkg_sysreqs as vector, |
update_cmd |
command used to update packages, "apt-get update -y" by default |
install_cmd |
command used to install packages, "apt-get install -y" by default |
clean_cmd |
command used to clean package folder, "rm -rf /var/lib/apt/lists/*" by default |
Value
vector of compacted command to run to install sysreqs
Examples
pkg_installs <- list("apt-get install -y htop", "apt-get install -y top")
compact_sysreqs(pkg_installs)
Create a Dockerfile from a DESCRIPTION
Description
Create a Dockerfile from a DESCRIPTION
Usage
dock_from_desc(
path = "DESCRIPTION",
FROM = paste0("rocker/r-ver:", R.Version()$major, ".", R.Version()$minor),
AS = NULL,
sysreqs = TRUE,
repos = c(CRAN = "https://p3m.dev/cran/latest"),
expand = FALSE,
update_tar_gz = TRUE,
build_from_source = TRUE,
extra_sysreqs = NULL,
github_pat = c("none", "build_arg", "secret"),
strict_install = TRUE
)
Arguments
path |
path to the DESCRIPTION file to use as an input. |
FROM |
The FROM of the Dockerfile. Default is
|
AS |
The build-stage name of the Dockerfile ( |
sysreqs |
boolean. If TRUE, the Dockerfile will contain sysreq installation. |
repos |
character. The URL(s) of the repositories to use for
|
expand |
boolean. If |
update_tar_gz |
boolean. If |
build_from_source |
boolean. If |
extra_sysreqs |
character vector. Extra debian system requirements.
Will be installed with apt-get install. Each entry must be a Debian
package name ( |
github_pat |
character. How to provide a GitHub PAT to
|
strict_install |
boolean. When |
Details
Two install strategies are available for the package itself:
-
build_from_source = TRUE(the default): the generated Dockerfile mounts the source folder and installs from it directly.update_tar_gzis ignored. -
build_from_source = FALSE: a source tarball (<pkg>_<version>.tar.gz) isCOPY'd into the image and installed withremotes::install_local(). Whenupdate_tar_gz = TRUE, a fresh tarball is built withpkgbuild::build()first (and any stale<pkg>_*.tar.gzin the current directory is removed); whenupdate_tar_gz = FALSE, an already-built tarball is expected alongside theDESCRIPTION.
The package name and its dependency-field names are read from the
DESCRIPTION and validated against the CRAN package-name grammar
before being interpolated into the generated directives.
Value
Dockerfile
Examples
## Not run:
# From the DESCRIPTION of the package in the working directory:
dock <- dock_from_desc("DESCRIPTION")
dock
# Pull source packages from the classic CRAN mirror instead of PPM:
dock_from_desc(
"DESCRIPTION",
repos = c(CRAN = "https://cran.rstudio.com/")
)
## End(Not run)
Create a Dockerfile from an renv.lock file
Description
Create a Dockerfile from an renv.lock file
Usage
dock_from_renv(
lockfile = "renv.lock",
distro = NULL,
FROM = "rocker/r-ver",
AS = NULL,
sysreqs = TRUE,
repos = c(CRAN = "https://p3m.dev/cran/latest"),
expand = FALSE,
extra_sysreqs = NULL,
use_pak = FALSE,
user = "rstudio",
dependencies = NA,
sysreqs_platform = "ubuntu",
renv_version,
github_pat = c("none", "build_arg", "secret"),
renv_paths_cache = NULL
)
Arguments
lockfile |
Path to an |
distro |
|
FROM |
Docker image to start FROM. Default is |
AS |
The AS of the Dockerfile. Default is |
sysreqs |
boolean. If |
repos |
character. The URL(s) of the repositories to use for
|
expand |
boolean. If |
extra_sysreqs |
character vector. Extra debian system requirements.
Will be installed with apt-get install. Each entry must be a Debian
package name ( |
use_pak |
boolean. If |
user |
Name of the user the runtime container drops privilege
to before the The Dockerfile is emitted in two halves: every step that needs
root (apt-get, R install commands, To make this work regardless of the FROM image, the package
emits a defensive Pass debian/ubuntu images only ( The argument is validated at codegen time against
|
dependencies |
What kinds of dependencies to install. Most commonly one of the following values:
|
sysreqs_platform |
System requirements platform. |
renv_version |
character or
When supplied as a string, validated as a version-like token
( |
github_pat |
character. How to provide a GitHub PAT to
|
renv_paths_cache |
character or When In all cases ( |
Details
System requirements for packages are provided
through RStudio Package Manager via the pak
package. The install commands provided from pak
are added as RUN directives within the Dockerfile.
The R version is taken from the renv.lock file.
Packages are installed using renv::restore() which ensures
that the proper package version and source is used when installed.
Value
A R6 object of class Dockerfile.
Examples
## Not run:
dock <- dock_from_renv("renv.lock")
dock$write("Dockerfile")
## End(Not run)
Create a dockerignore file
Description
Create a dockerignore file
Usage
docker_ignore_add(path)
Arguments
path |
Where to write the file |
Value
The path to the .dockerignore file, invisibly.
Examples
## Not run:
docker_ignore_add()
## End(Not run)
Get system requirements
Description
This function retrieves information about the
system requirements using the pak::pkg_sysreqs().
Usage
get_sysreqs(packages, quiet = TRUE, batch_n = 30)
Arguments
packages |
character vector. Packages names. |
quiet |
Boolean. If |
batch_n |
numeric. Number of simultaneous packages to ask. |
Value
A vector of system requirements.
Examples
## Not run:
get_sysreqs("glue")
get_sysreqs(c("curl", "xml2"))
## End(Not run)
Parse a Dockerfile
Description
Create a Dockerfile object from a Dockerfile.
Usage
parse_dockerfile(path)
Arguments
path |
path to the Dockerfile |
Value
A Dockerfile object
Examples
parse_dockerfile(system.file("Dockerfile", package = "dockerfiler"))
Turn an R expression into a shell R -e '...' call
Description
Captures an R expression unevaluated and renders it as a single
shell-quoted R -e '...' string, suitable for a Dockerfile
$RUN() directive.
Usage
r(code)
Arguments
code |
an R expression (captured unevaluated) to wrap. |
Value
a length-1 character string of the form R -e '...',
shell-quoted with base::shQuote().
Examples
r(print("yeay"))
r(install.packages("plumber", repos = "https://cloud.r-project.org"))