dockerfiler is now on CRAN

March 1, 2018
By

(This article was first published on Colin Fay, and kindly contributed to R-bloggers)

{dockerfiler} is a package that comes with a simple, object oriented API for Dockerfile creation, straight from your R session. Now on CRAN.

Installation

You can install {dockerfiler} from GitHub with:

# install.packages("remotes")
remotes::install_github("colinfay/dockerfiler")

Or from CRAN with :

install.packages("dockerfiler")

Basic worflow

By default, Dockerfiles are created with FROM "rocker/r-base". You can
set another FROM in new()

library(dockerfiler)
# Create a dockerfile template
my_dock <- Dockerfile$new()
my_dock$MAINTAINER("Colin FAY", "[email protected]")

Wrap your raw R Code inside the r() function to turn it into a bash
command with R
-e
.

my_dock$RUN(r(install.packages("attempt", repo = "http://cran.irsn.fr/")))

Classical Docker stuffs:

my_dock$RUN("mkdir /usr/scripts")
my_dock$RUN("cd /usr/scripts")
my_dock$COPY("plumberfile.R", "/usr/scripts/plumber.R")
my_dock$COPY("torun.R", "/usr/scripts/torun.R")
my_dock$EXPOSE(8000)
my_dock$CMD("Rscript /usr/scripts/torun.R ")

See your Dockerfile :

my_dock
## FROM rocker/r-base
## MAINTAINER Colin FAY 
## RUN R -e 'install.packages("attempt", repo = "http://cran.irsn.fr/")'
## RUN mkdir /usr/scripts
## RUN cd /usr/scripts
## COPY plumberfile.R /usr/scripts/plumber.R
## COPY torun.R /usr/scripts/torun.R
## EXPOSE 8000
## CMD Rscript /usr/scripts/torun.R

If you’ve made a mistake in your script, you can switch lines with the
switch_cmd method. This function takes as arguments the positions of
the two cmd you want to switch :

# Switch line 8 and 7
my_dock$switch_cmd(8, 7)
my_dock
## FROM rocker/r-base
## MAINTAINER Colin FAY 
## RUN R -e 'install.packages("attempt", repo = "http://cran.irsn.fr/")'
## RUN mkdir /usr/scripts
## RUN cd /usr/scripts
## COPY plumberfile.R /usr/scripts/plumber.R
## EXPOSE 8000
## COPY torun.R /usr/scripts/torun.R
## CMD Rscript /usr/scripts/torun.R

You can also remove a cmd with remove_cmd:

my_dock$remove_cmd(8)
my_dock
## FROM rocker/r-base
## MAINTAINER Colin FAY 
## RUN R -e 'install.packages("attempt", repo = "http://cran.irsn.fr/")'
## RUN mkdir /usr/scripts
## RUN cd /usr/scripts
## COPY plumberfile.R /usr/scripts/plumber.R
## EXPOSE 8000
## CMD Rscript /usr/scripts/torun.R

This also works with a vector:

my_dock$remove_cmd(5:7)
my_dock
## FROM rocker/r-base
## MAINTAINER Colin FAY 
## RUN R -e 'install.packages("attempt", repo = "http://cran.irsn.fr/")'
## RUN mkdir /usr/scripts
## CMD Rscript /usr/scripts/torun.R

Save your Dockerfile:

my_dock$write()

Contact

Questions and feedbacks welcome!

You want to contribute ? Open a
PR 🙂 If you encounter
a bug or want to suggest an enhancement, please open an
issue
.

To leave a comment for the author, please follow the link and comment on their blog: Colin Fay.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)