Learn R Programming

containerit

containerit packages R script/session/workspace and all dependencies as a Docker container by automagically generating a suitable Dockerfile. The package’s website is https://o2r.info/containerit/.

Prerequisites

  • containerit only fully works if you have Docker installed and is only tested with Docker Engine - Community (previously called Docker Community Edition or Docker CE).
  • R (>= 3.5.0) is needed so that some dependencies (e.g. BiocManager) are available; older versions of R predate the development of the package and were never tested.

Quick start

Try out containerit in a container

You can spin up a Docker container with containerit pre-installed if you want to try out the package. The default of the containerit images on Docker Hub is to start plain R, but you can also start an with RStudio session in a browser.

Note: The geospatial variant is used so that examples from containerit vignettes are likely to work. For a minimal Dockerfile to run containerit, see inst/docker/minimal/Dockerfile.

docker run --rm -it -e PASSWORD=o2r -p 8787:8787 o2rproject/containerit:geospatial /init

Now go to http://localhost:8787 and log in with the user rstudio and password o2r. Continue in section Use.

Install

Installation is only possible from GitHub:

# install.packages("remotes")
remotes::install_github("o2r-project/containerit")

Use

containerit can create Dockerfile objects in R and render them as Dockerfile instructions based on session information objects or runnable R files (.R, .Rmd).

suppressPackageStartupMessages(library("containerit"))
my_dockerfile <- containerit::dockerfile(from = utils::sessionInfo())
#> INFO [2019-08-20 10:10:52] Going online? TRUE  ... to retrieve system dependencies (sysreq-api)
#> INFO [2019-08-20 10:10:52] Trying to determine system requirements for the package(s) 'assertthat,backports,crayon,curl,desc,digest,evaluate,formatR,fs,futile.logger,futile.options,htmltools,httpuv,jsonlite,knitr,lambda.r,later,magrittr,mime,miniUI,pillar,pkgconfig,promises,R6,Rcpp,rlang,rmarkdown,rprojroot,semver,shiny,shinyFiles,stevedore,stringi,stringr,tibble,versions,xfun,xtable,yaml' from sysreqs online DB
#> INFO [2019-08-20 10:11:25] Adding CRAN packages: assertthat, backports, crayon, curl, desc, digest, evaluate, formatR, fs, futile.logger, futile.options, htmltools, httpuv, jsonlite, knitr, lambda.r, later, magrittr, mime, miniUI, pillar, pkgconfig, promises, R6, Rcpp, rlang, rmarkdown, rprojroot, semver, shiny, shinyFiles, stevedore, stringi, stringr, tibble, versions, xfun, xtable, yaml
#> INFO [2019-08-20 10:11:25] Created Dockerfile-Object based on sessionInfo
print(my_dockerfile)
#> FROM rocker/r-ver:3.6.1
#> LABEL maintainer="daniel"
#> RUN ["install2.r", "assertthat", "backports", "crayon", "curl", "desc", "digest", "evaluate", "formatR", "fs", "futile.logger", "futile.options", "htmltools", "httpuv", "jsonlite", "knitr", "lambda.r", "later", "magrittr", "mime", "miniUI", "pillar", "pkgconfig", "promises", "R6", "Rcpp", "rlang", "rmarkdown", "rprojroot", "semver", "shiny", "shinyFiles", "stevedore", "stringi", "stringr", "tibble", "versions", "xfun", "xtable", "yaml"]
#> WORKDIR /payload/
#> CMD ["R"]

You can disable logging:

futile.logger::flog.threshold(futile.logger::ERROR)

Now we create a Dockerfile for a specific R version and R Markdown file and do not add any packages already available in the base image:

rmd_dockerfile <- containerit::dockerfile(from = "inst/demo.Rmd",
                                          image = "rocker/verse:3.5.2",
                                          maintainer = "o2r",
                                          filter_baseimage_pkgs = TRUE)
#> Detected API version '1.40' is above max version '1.39'; downgrading
#> Detected API version '1.40' is above max version '1.39'; downgrading
print(rmd_dockerfile)
#> FROM rocker/verse:3.5.2
#> LABEL maintainer="o2r"
#> # CRAN packages skipped because they are in the base image: assertthat, backports, cli, crayon, curl, desc, digest, evaluate, formatR, fs, htmltools, httpuv, jsonlite, knitr, later, magrittr, mime, miniUI, pillar, pkgconfig, promises, R6, Rcpp, rlang, rmarkdown, rprojroot, rstudioapi, sessioninfo, shiny, stringi, stringr, tibble, withr, xfun, xtable, yaml
#> RUN ["install2.r", "fortunes", "futile.logger", "futile.options", "lambda.r", "semver", "shinyFiles", "stevedore", "versions"]
#> WORKDIR /payload/
#> CMD ["R"]

For extended instructions, see the vignettes at in the directory vignettes/, which are readable online at https://o2r.info/containerit/articles/.

Images

Images are available starting from different base images. All images are also available with version tags.

The Dockerfiles are available in the directory inst/docker/Dockerfile.

verse

docker inspect o2rproject/containerit

Base image: rocker/verse:3.5.3

geospatial

docker inspect o2rproject/containerit:geospatial

Base image: rocker/geospatial:3.5.3

RStudio Add-in

RStudio Addins allow to create interactive user interfaces for the RStudio development environment. Courtesy of a great contribution by a group of enthusiasts at the ROpenSci OZ Unconference 2018, there are several forms to quickly create Dockefiles from different use cases, e.g. the current session, a vector of expressions, or a script file.

Contribute

All help is welcome: asking questions, providing documentation, testing, or even development.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

See CONTRIBUTING.md for details.

Development

r-hub builder is great for running checks, e.g. before submitting to CRAN and on other operating systems.

library("rhub")
rhub::check_for_cran()
rhub::check_on_windows()

You can build the pkgdown site with

pkgdown::build_site()

You can build the Docker images locally with the current development version using the following commands.

docker build --tag containerit:dev --file inst/docker/Dockerfile.local .
docker build --tag containerit:geospatial-dev --file inst/docker/geospatial/Dockerfile.local .

You can use pre-commit hooks to avoid some mistakes.

A codemeta file, codemeta.json, with metadata about the package and its dependencies is generated automatically when this document is compiled.

codemetar::write_codemeta("containerit")

License

containerit is licensed under GNU General Public License, version 3, see file LICENSE.

Copyright (C) 2019 - o2r project.

Copy Link

Version

Version

0.6.0

License

GPL-3 + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

January 1st, 1970

Functions in containerit (0.6.0)

Copy-class

S4 Class representing a COPY-instruction
extract_session_file

Reads a sessionInfo object from an RData file
Dockerfile-class

An S4 class to represent a Dockerfile
Label-class

Instruction class representing a LABEL
Stopsignal-class

Stopsignal-instruction class yet to be implemented
Entrypoint-class

Entrypoint class yet to be implemented
Shell

Shell constructor yet to be implemented
Label

Creates a label of arbitrary content
dockerfile

dockerfile-method
Entrypoint

Constructor for ENTRYPOINT instruction
Env

Constructor for Env yet to be implemented
Expose-class

S4 Class representing an EXPOSE-instruction
Label_SessionInfo

Creates a label holding R session information
Label_Maintainer

Create Label corresponding to the maintainer field
LabelSchemaFactory

Create Build-time labels according to Label Schema Convention
From-class

An S4 class to represent a FROM instrunction relating to a Docker image
Expose

Constructor for EXPOSE instruction
Copy

Constructor for COPY instruction
Healthcheck-class

Healthcheck-instruction class yet to be implemented
From

create objects of class From
Run

Create objects representing a RUN instruction
Env-class

Env class yet to be implemented
Add

Add constructor yet to be implemented
Run_shell

Create objects representing a RUN instruction in shell form
Shell-class

Shell-instruction class yet to be implemented
Instruction-class

The Docker Instruction - Class
Healthcheck

Healthcheck constructor yet to be implemented
characterOrInteger-class

Class union for slots taking either numeric or character input
Run_shell-class

An S4 class to represent a RUN instruction in shell form
Maintainer-class

An S4 class to represent a Dockerfile's maintainer
Workdir

Constructor for a WORKDIR instruction
as.character,Dockerfile-method

Convert a Dockerfile to String
Maintainer

Create MAINTAINER instructions
clean_session

Obtains a sessionInfo from a local R session
addInstruction<-

Add one or more instructions to a Dockerfile
getGitHubRef

Get GitHub reference from package
Workdir-class

S4 Class representing a WORKDIR instruction
getImageForVersion

getImageForVersion-method
Volume

Constructor for Volume yet to be implemented
Run-class

An S4 class to represent a RUN instruction
Onbuild

Onbuild constructor yet to be implemented
toString,Instruction-method

Convert an Instruction-object to a string holding a Docker instruction
as.character,Instruction-method

Convert an Instruction-object to a string holding a Docker instruction
Onbuild-class

Onbuild-instruction class yet to be implemented
extract_session_image

Optains a session info from R executed in a container
print,Dockerfile-method

Print a Dockerfile
parseFrom

Parse a From-instruction from an image-argument
containerit

containerit: A package for packaging R objects and their dependencies in software containers
getRVersionTag

Get R version in string format used for image tags
containerit_write_config

Re - init (overwrite) current package configuration
get_installed_packages

Detect packages in a Docker image
containerit-addin

Helper function for RStudio Addin user interface
Stopsignal

Stopsignal constructor yet to be implemented
Volume-class

Volume class yet to be implemented
format,Dockerfile-method

Format a Dockerfile
docker_build

Build a Docker image from a local Dockerfile or a Dockerfile object
write,Dockerfile-method

Write a Dockerfile object to a dockerfile
toString,Dockerfile-method

Convert a Dockerfile to String
print,Instruction-method

Print an Instruction
versioned_install_instructions

Helper function for installing versioned R packages
Arg-class

Arg-instruction class yet to be implemented
Comment-class

Instructionclass representing a comment
Cmd

create objects representing a CMD instruction
Comment

Creates a comment with character content
Add-class

Add-instruction class yet to be implemented
Cmd-class

An S4 class to represent a CMD instruction
CMD_Render

Create CMD instruction for rendering a markdown file
Arg

Arg constructor yet to be implemented
CMD_Rscript

Create CMD instruction for running an R script