<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Using the containerit Docker image • containerit</title>
<!-- jquery --><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script><!-- Bootstrap --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous">
<!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script><!-- sticky kit --><script src="https://cdnjs.cloudflare.com/ajax/libs/sticky-kit/1.1.3/sticky-kit.min.js" integrity="sha256-c4Rlo1ZozqTPE2RLuvbusY3+SU1pQaJC0TjuhygMipw=" crossorigin="anonymous"></script><!-- pkgdown --><link href="../pkgdown.css" rel="stylesheet">
<script src="../pkgdown.js"></script><meta property="og:title" content="Using the containerit Docker image">
<meta property="og:description" content="">
<meta property="og:image" content="/logo.png">
<meta name="twitter:card" content="summary">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
    <div class="container template-article">
      <header><div class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <span class="navbar-brand">
        <a class="navbar-link" href="../index.html">containerit</a>
        <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.6.0</span>
      </span>
    </div>

    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
<li>
  <a href="../index.html">
    <span class="fa fa-home fa-lg"></span>
     
  </a>
</li>
<li>
  <a href="../articles/containerit.html">Get started</a>
</li>
<li>
  <a href="../reference/index.html">Reference</a>
</li>
<li class="dropdown">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
    Articles
     
    <span class="caret"></span>
  </a>
  <ul class="dropdown-menu" role="menu">
<li>
      <a href="../articles/basic.html">Basic introduction to package containerit</a>
    </li>
    <li>
      <a href="../articles/bioconductor.html">Using Bioconductor with containerit</a>
    </li>
    <li>
      <a href="../articles/container.html">Using the containerit Docker image</a>
    </li>
  </ul>
</li>
<li>
  <a href="../news/index.html">Changelog</a>
</li>
      </ul>
<ul class="nav navbar-nav navbar-right">
<li>
  <a href="https://github.com/o2r-project/containerit">
    <span class="fa fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
</div>
<!--/.nav-collapse -->
  </div>
<!--/.container -->
</div>
<!--/.navbar -->

      
      </header><div class="row">
  <div class="col-md-9 contents">
    <div class="page-header toc-ignore">
      <h1>Using the containerit Docker image</h1>
                        <h4 class="author">Daniel Nüst</h4>
            
            <h4 class="date">2019-08-20</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/o2r-project/containerit/blob/master/vignettes/container.Rmd"><code>vignettes/container.Rmd</code></a></small>
      <div class="hidden name"><code>container.Rmd</code></div>

    </div>

    
    
<!-- Copyright 2018 Opening Reproducible Research (https://o2r.info) -->
<div id="introduction" class="section level2">
<h2 class="hasAnchor">
<a href="#introduction" class="anchor"></a>Introduction</h2>
<p>Containerit is also available itself as a ready-to-use Docker image from <a href="https://hub.docker.com/r/o2rproject/containerit/">Docker Hub</a>. This is useful if you do not want to install a full stack of packages in your local machine, but still trace a specific R session/script/document using a regular command line interface.</p>
</div>
<div id="tldr---pull-image-and-show-dockerfile-on-console" class="section level2">
<h2 class="hasAnchor">
<a href="#tldr---pull-image-and-show-dockerfile-on-console" class="anchor"></a>tl;dr - pull image and show Dockerfile on console</h2>
<p>The following example pulls the <code>geospatial</code> variant of the containerit images, runs two R commands, and prints out the created Dockerfile to the console.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb1-1" data-line-number="1"><span class="ex">docker</span> pull o2rproject/containerit:geospatial</a>
<a class="sourceLine" id="cb1-2" data-line-number="2"><span class="ex">docker</span> run --rm o2rproject/containerit:geospatial R -e <span class="st">"library(sf); the_dockerfile &lt;- containerit::dockerfile(); print(the_dockerfile);"</span></a></code></pre></div>
<pre><code>## geospatial: Pulling from o2rproject/containerit
## c5e155d5a1d1: Already exists
## 2524371be50d: Already exists
## 03321dce714a: Already exists
## f7183dc9df43: Already exists
## 8a94f51ef612: Already exists
## 0871071b8282: Already exists
## d20d9e24f0ce: Already exists
## ecd0c9d884a2: Already exists
## 34198166c3ef: Already exists
## 89978b67f5d2: Already exists
## 005de089cb1e: Already exists
## 5fe456ccc50f: Already exists
## a4bbc4ae328f: Pulling fs layer
## b648dceb1c63: Pulling fs layer
## 2801e53bec76: Pulling fs layer
## 9494b804300f: Pulling fs layer
## 2801e53bec76: Verifying Checksum
## 2801e53bec76: Download complete
## a4bbc4ae328f: Verifying Checksum
## a4bbc4ae328f: Download complete
## a4bbc4ae328f: Pull complete
## 9494b804300f: Download complete
## b648dceb1c63: Verifying Checksum
## b648dceb1c63: Download complete
## b648dceb1c63: Pull complete
## 2801e53bec76: Pull complete
## 9494b804300f: Pull complete
## Digest: sha256:98de04565b5c6df876a00f1283ed8d9f84d5ac3925ac7ddabfe0592b25b89724
## Status: Downloaded newer image for o2rproject/containerit:geospatial
## docker.io/o2rproject/containerit:geospatial
## 
## R version 3.5.3 (2019-03-11) -- "Great Truth"
## Copyright (C) 2019 The R Foundation for Statistical Computing
## Platform: x86_64-pc-linux-gnu (64-bit)
## 
## R is free software and comes with ABSOLUTELY NO WARRANTY.
## You are welcome to redistribute it under certain conditions.
## Type 'license()' or 'licence()' for distribution details.
## 
## R is a collaborative project with many contributors.
## Type 'contributors()' for more information and
## 'citation()' on how to cite R or R packages in publications.
## 
## Type 'demo()' for some demos, 'help()' for on-line help, or
## 'help.start()' for an HTML browser interface to help.
## Type 'q()' to quit R.
## 
## &gt; library(sf); the_dockerfile &lt;- containerit::dockerfile(); print(the_dockerfile);
## Linking to GEOS 3.5.1, GDAL 2.1.2, PROJ 4.9.3
## INFO [2019-08-20 14:45:10] Going online? TRUE  ... to retrieve system dependencies (sysreq-api)
## INFO [2019-08-20 14:45:10] Trying to determine system requirements for the package(s) 'assertthat,backports,class,classInt,crayon,curl,DBI,desc,digest,e1071,formatR,fs,futile.logger,futile.options,htmltools,httpuv,jsonlite,lambda.r,later,magrittr,mime,miniUI,pillar,pkgconfig,promises,R6,Rcpp,rlang,rprojroot,semver,sf,shiny,shinyFiles,stevedore,stringi,stringr,tibble,units,versions,xtable' from sysreqs online DB
## INFO [2019-08-20 14:45:13] Adding CRAN packages: assertthat, backports, class, classInt, crayon, curl, DBI, desc, digest, e1071, formatR, fs, futile.logger, futile.options, htmltools, httpuv, jsonlite, lambda.r, later, magrittr, mime, miniUI, pillar, pkgconfig, promises, R6, Rcpp, rlang, rprojroot, semver, sf, shiny, shinyFiles, stevedore, stringi, stringr, tibble, units, versions, xtable
## INFO [2019-08-20 14:45:13] Created Dockerfile-Object based on sessionInfo
## FROM rocker/r-ver:3.5.3
## LABEL maintainer="root"
## RUN export DEBIAN_FRONTEND=noninteractive; apt-get -y update \
##   &amp;&amp; apt-get install -y gdal-bin \
##  libcurl4-openssl-dev \
##  libgdal-dev \
##  libgeos-dev \
##  libgeos++-dev \
##  libssl-dev \
##  libudunits2-dev \
##  make
## RUN ["install2.r", "assertthat", "backports", "class", "classInt", "crayon", "curl", "DBI", "desc", "digest", "e1071", "formatR", "fs", "futile.logger", "futile.options", "htmltools", "httpuv", "jsonlite", "lambda.r", "later", "magrittr", "mime", "miniUI", "pillar", "pkgconfig", "promises", "R6", "Rcpp", "rlang", "rprojroot", "semver", "sf", "shiny", "shinyFiles", "stevedore", "stringi", "stringr", "tibble", "units", "versions", "xtable"]
## WORKDIR /payload/
## CMD ["R"]
## &gt; 
## &gt; 
## 
## R version 3.5.3 (2019-03-11)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Debian GNU/Linux 9 (stretch)
## 
## Matrix products: default
## BLAS: /usr/lib/openblas-base/libblas.so.3
## LAPACK: /usr/lib/libopenblasp-r0.2.19.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] sf_0.7-4            containerit_0.6.0   futile.logger_1.4.3
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.1           pillar_1.3.1         compiler_3.5.3      
##  [4] later_0.8.0          formatR_1.6          futile.options_1.0.1
##  [7] class_7.3-15         tools_3.5.3          digest_0.6.18       
## [10] jsonlite_1.6         tibble_2.1.1         stevedore_0.9.1     
## [13] pkgconfig_2.0.2      rlang_0.3.4          shiny_1.3.2         
## [16] DBI_1.0.0            curl_3.3             e1071_1.7-1         
## [19] stringr_1.4.0        desc_1.2.0           fs_1.2.7            
## [22] shinyFiles_0.7.2     versions_0.3         grid_3.5.3          
## [25] classInt_0.3-1       rprojroot_1.3-2      R6_2.4.0            
## [28] semver_0.2.0         lambda.r_1.2.3       magrittr_1.5        
## [31] units_0.6-2          backports_1.1.4      promises_1.0.1      
## [34] htmltools_0.3.6      assertthat_0.2.1     mime_0.6            
## [37] xtable_1.8-4         httpuv_1.5.1         stringi_1.4.3       
## [40] miniUI_0.1.1.1       rjson_0.2.20         crayon_1.3.4        
## 
##                                             CRAN 
## "https://mran.microsoft.com/snapshot/2019-04-26"</code></pre>
</div>
<div id="control-output" class="section level2">
<h2 class="hasAnchor">
<a href="#control-output" class="anchor"></a>Control output</h2>
<p>By default the containerit images print the session info before R is terminated. You can disable this by setting the environment variable <code>CONTAINERIT_SILENT</code>. Combined with the <code>--quiet</code> option for R, this reduces the output to merely the Dockerfile</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb3-1" data-line-number="1"><span class="ex">docker</span> run --rm -e CONTAINERIT_SILENT=true o2rproject/containerit:geospatial R -q -e <span class="st">"the_dockerfile &lt;- dockerfile(); print(the_dockerfile);"</span></a></code></pre></div>
<p>You can set the <a href="https://github.com/zatonovo/futile.logger#thresholds">futile.logger threshold</a> with the environment variable <code>CONTAINERIT_FLOG_THRESHOLD</code> to <code>ERROR</code>, <code>WARN</code> or <code>DEBUG</code>; default is <code>INFO</code>.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="ex">docker</span> run --rm -e CONTAINERIT_SILENT=true -e CONTAINERIT_FLOG_THRESHOLD=WARN o2rproject/containerit:geospatial R -q -e <span class="st">"the_dockerfile &lt;- dockerfile(); print(the_dockerfile);"</span></a></code></pre></div>
</div>
<div id="save-file" class="section level2">
<h2 class="hasAnchor">
<a href="#save-file" class="anchor"></a>Save file</h2>
<p>You can of course also mount a directory with write permissions and save the Dockerfile. The default directory in the container is <code>/containerit</code>, so you can mount to this location and write the Dockerfile object:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="fu">mkdir</span> /tmp/containerit</a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="ex">docker</span> run --rm -v /tmp/containerit:/containerit -e CONTAINERIT_SILENT=true -e CONTAINERIT_FLOG_THRESHOLD=WARN o2rproject/containerit:geospatial R -q -e <span class="st">"the_dockerfile &lt;- dockerfile(); write(the_dockerfile);"</span></a>
<a class="sourceLine" id="cb5-3" data-line-number="3"><span class="bu">echo</span> Directory contents:</a>
<a class="sourceLine" id="cb5-4" data-line-number="4"><span class="fu">ls</span> -l /tmp/containerit</a>
<a class="sourceLine" id="cb5-5" data-line-number="5"><span class="fu">rm</span> -r /tmp/containerit</a></code></pre></div>
<p>Or you can use full paths, as shown below. The next example also sets the <a href="https://github.com/rocker-org/rocker/wiki/managing-users-in-docker">user of the container</a>, so that the file on the host has a more convenient user and permissions.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb6-1" data-line-number="1"><span class="fu">mkdir</span> /tmp/containerit</a>
<a class="sourceLine" id="cb6-2" data-line-number="2"><span class="ex">docker</span> run --rm -v /tmp/containerit:/my_dir -e CONTAINERIT_SILENT=true -e CONTAINERIT_FLOG_THRESHOLD=WARN --user=1000 o2rproject/containerit:geospatial R -q -e <span class="st">"the_dockerfile &lt;- dockerfile(); write(the_dockerfile,file = '/my_dir/Dockerfile');"</span></a>
<a class="sourceLine" id="cb6-3" data-line-number="3"><span class="bu">echo</span> Directory contents:</a>
<a class="sourceLine" id="cb6-4" data-line-number="4"><span class="fu">ls</span> -l /tmp/containerit</a>
<a class="sourceLine" id="cb6-5" data-line-number="5"><span class="fu">rm</span> -r /tmp/containerit</a></code></pre></div>
</div>
<div id="example-package-script" class="section level2">
<h2 class="hasAnchor">
<a href="#example-package-script" class="anchor"></a>Example: package script</h2>
<div class="sourceCode" id="cb7"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb7-1" data-line-number="1"><span class="fu">mkdir</span> /tmp/containerit</a>
<a class="sourceLine" id="cb7-2" data-line-number="2"><span class="bu">echo</span> <span class="st">"install.packages('fortunes', repos = 'https://cran.r-project.org'); fortunes::fortune();"</span> <span class="op">&gt;&gt;</span> /tmp/containerit/script.R</a>
<a class="sourceLine" id="cb7-3" data-line-number="3"></a>
<a class="sourceLine" id="cb7-4" data-line-number="4"><span class="ex">docker</span> run --rm -v /tmp/containerit:/data o2rproject/containerit R -q -e <span class="st">"setwd('/data'); scriptFile &lt;- 'script.R'; write(dockerfile(from = scriptFile, cmd = CMD_Rscript(basename(scriptFile))));"</span></a>
<a class="sourceLine" id="cb7-5" data-line-number="5"></a>
<a class="sourceLine" id="cb7-6" data-line-number="6"><span class="fu">cat</span> /tmp/containerit/Dockerfile</a>
<a class="sourceLine" id="cb7-7" data-line-number="7"><span class="fu">rm</span> -r /tmp/containerit</a></code></pre></div>
</div>
<div id="build-image-locally" class="section level2">
<h2 class="hasAnchor">
<a href="#build-image-locally" class="anchor"></a>Build image locally</h2>
<p>With the following commands you can build an image from the local source code. The following commands executed in the <code>containerit</code> source directory create an image <code>containerit:geo-manual</code> and run it to create a <code>Dockerfile</code>:</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb8-1" data-line-number="1"><span class="ex">docker</span> build --file ../inst/docker/geospatial/Dockerfile --tag containerit:geo-manual .</a>
<a class="sourceLine" id="cb8-2" data-line-number="2"><span class="ex">docker</span> run --rm containerit:geo-manual R -e <span class="st">"library(sf); the_dockerfile &lt;- containerit::dockerfile(); print(the_dockerfile);"</span></a></code></pre></div>
<p>You can try the <code>predetect</code> feature by packaging the R Markdown file of the second spacetime vignette with the non-<code>geospatial</code> image of containerit that was just built. The following command will install missing packages before running the file, namely <code>sf</code> itself, but it’s installation will fail due to missing system dependencies, which are not covered by predetection.</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb9-1" data-line-number="1"><span class="ex">docker</span> run --rm -i -v <span class="va">$(</span><span class="bu">pwd</span><span class="va">)</span>/tests/testthat/package_markdown/sfr:/erc -e CONTAINERIT_FLOG_THRESHOLD=DEBUG containerit R --quiet -e <span class="st">"setwd('/erc'); list.files(); print(dockerfile(from = '.'))"</span></a></code></pre></div>
</div>
  </div>

  <div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
        <div id="tocnav">
      <h2 class="hasAnchor">
<a href="#tocnav" class="anchor"></a>Contents</h2>
      <ul class="nav nav-pills nav-stacked">
<li><a href="#introduction">Introduction</a></li>
      <li><a href="#tldr---pull-image-and-show-dockerfile-on-console">tl;dr - pull image and show Dockerfile on console</a></li>
      <li><a href="#control-output">Control output</a></li>
      <li><a href="#save-file">Save file</a></li>
      <li><a href="#example-package-script">Example: package script</a></li>
      <li><a href="#build-image-locally">Build image locally</a></li>
      </ul>
</div>
      </div>

</div>


      <footer><div class="copyright">
  <p>Developed by Daniel Nuest, Matthias Hinz.</p>
</div>

<div class="pkgdown">
  <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.3.0.</p>
</div>
      </footer>
</div>

  

  </body>
</html>
