<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/why-use-docker-with-r-a-devops-perspective/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.opencpu.org/posts/opencpu-with-docker/"> OpenCPU</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p> <a rel="nofollow" href="https://www.opencpu.org/posts/opencpu-with-docker" target="_blank"><img alt="opencpu logo" src="https://i1.wp.com/www.opencpu.org/images/stockplot.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<p>There have been several blog posts going around about why one would use Docker with R.<br>
In this post I’ll try to add a DevOps point of view and explain how containerizing<br>
R is used in the context of the OpenCPU system for building and deploying R servers.</p>
<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">Has anyone in the <a rel="nofollow" href="https://twitter.com/hashtag/rstats?src=hash&ref_src=twsrc%5Etfw" target="_blank">#rstats</a> world written really well about the *why* of their use of Docker, as opposed to the the *how*?</p>
<p>— Jenny Bryan (@JennyBryan) <a rel="nofollow" href="https://twitter.com/JennyBryan/status/913785731998289920?ref_src=twsrc%5Etfw" target="_blank">September 29, 2017</a></p></blockquote>
<p></p>
<h2>1: Easy Development</h2>
<p>The flagship of the OpenCPU system is the <a rel="nofollow" href="https://www.opencpu.org/download.html" target="_blank">OpenCPU server</a>:<br>
a mature and powerful Linux stack for embedding R in systems and applications.<br>
Because OpenCPU is completely open source we can build and ship on DockerHub. A ready-to-go linux server with both OpenCPU and RStudio<br>
can be started using the following (use port 8004 or 80):</p>
<div>
<pre><code>docker run -t -p 8004:8004 opencpu/rstudio
</code></pre>
</div>
<p>Now simply open <a rel="nofollow" href="http://localhost:8004/ocpu/" target="_blank">http://localhost:8004/ocpu/</a> and<br>
<a rel="nofollow" href="http://localhost:8004/rstudio/" target="_blank">http://localhost:8004/rstudio/</a> in your browser!<br>
Login via rstudio with user: <code>opencpu</code> (passwd: <code>opencpu</code>) to build or install apps.<br>
See the <a rel="nofollow" href="https://hub.docker.com/r/opencpu/rstudio/" target="_blank">readme</a> for more info.</p>
<p>Docker makes it easy to get started with OpenCPU. The container gives you the full<br>
flexibility of a Linux box, without the need to install anything on your system.<br>
You can install packages or apps via rstudio server, or use <code>docker exec</code> to a<br>
root shell on the running server:</p>
<div>
<pre><code># Lookup the container ID
docker ps

# Drop a shell
docker exec -i -t eec1cdae3228 /bin/bash
</code></pre>
</div>
<p>From the shell you can install additional software in the server, customize the apache2 httpd<br>
config (auth, proxies, etc), tweak R options, optimize performance by preloading data or<br>
packages, etc.</p>
<h2>2: Shipping and Deployment via DockerHub</h2>
<p>The most powerful use if Docker is shipping and deploying applications via DockerHub. To create a fully standalone<br>
application container, simply use a standard <a rel="nofollow" href="https://hub.docker.com/u/opencpu/" target="_blank">opencpu image</a><br>
and add your app.</p>
<p>For the purpose of this blog post I have wrapped up some of the <a rel="nofollow" href="https://www.opencpu.org/apps.html" target="_blank">example apps</a> as docker containers by adding a very simple <code>Dockerfile</code> to each repository. For example the <a rel="nofollow" href="https://rwebapps.ocpu.io/nabel/www/" target="_blank">nabel</a> app has a <a rel="nofollow" href="https://github.com/rwebapps/nabel/blob/master/Dockerfile" target="_blank">Dockerfile</a> that contains the following:</p>
<div>
<pre><code>FROM opencpu/base

RUN R -e 'devtools::install_github(&quot;rwebapps/nabel&quot;)'
</code></pre>
</div>
<p>It takes the standard <a rel="nofollow" href="https://hub.docker.com/r/opencpu/base/" target="_blank">opencpu/base</a><br>
image and then installs the nabel app from the Github <a rel="nofollow" href="https://github.com/rwebapps" target="_blank">repository</a>.<br>
The result is a completeley isolated, standalone application. The application can be<br>
started by anyone using e.g:</p>
<div>
<pre><code>docker run -d 8004:8004 rwebapps/nabel
</code></pre>
</div>
<p>The <code>-d</code> daemonizes on port 8004.<br>
Obviously you can tweak the <code>Dockerfile</code> to install whatever extra software or settings you need<br>
for your application.</p>
<p>Containerized deployment shows the true power of docker: it allows for shipping fully<br>
self contained appliations that work out of the box, without installing any software or<br>
relying on paid hosting services. If you do prefer professional hosting, there are<br>
many companies that will gladly host docker applications for you on scalable infrastructure.</p>
<h2>3 Cross Platform Building</h2>
<p>There is a third way Docker is used for OpenCPU. At each release we build<br>
the <code>opencpu-server</code> installation package for half a dozen operating systems, which<br>
get published on <a rel="nofollow" href="https://archive.opencpu.org/" target="_blank">https://archive.opencpu.org</a>.<br>
This process has been fully automated using DockerHub. The following images automatically<br>
build the enitre stack from source:</p>
<ul>
<li><a rel="nofollow" href="https://hub.docker.com/r/opencpu/ubuntu-16.04/" target="_blank">opencpu/ubuntu-16.04</a></li>
<li><a rel="nofollow" href="https://hub.docker.com/r/opencpu/debian-9/" target="_blank">opencpu/debian-9</a></li>
<li><a rel="nofollow" href="https://hub.docker.com/r/opencpu/fedora-25/" target="_blank">opencpu/fedora-25</a></li>
<li><a rel="nofollow" href="https://hub.docker.com/r/opencpu/fedora-26/" target="_blank">opencpu/fedora-26</a></li>
<li><a rel="nofollow" href="https://hub.docker.com/r/opencpu/centos-6/" target="_blank">opencpu/centos-6</a></li>
<li><a rel="nofollow" href="https://hub.docker.com/r/opencpu/centos-7/" target="_blank">opencpu/centos-7</a></li>
</ul>
<p>DockerHub automatically rebuilds this images when a new release is published on Github.<br>
All that is left to do is run a <a rel="nofollow" href="https://github.com/opencpu/archive/blob/gh-pages/update.sh" target="_blank">script</a><br>
which pull down the images and copies the <code>opencpu-server</code> binaries to the <a rel="nofollow" href="https://archive.opencpu.org/" target="_blank">archive server</a>.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://www.opencpu.org/posts/opencpu-with-docker/"> OpenCPU</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/4srvfM_YPTA" height="1"></a></div>