Shiny Server on Docker: CentOS 7 Edition
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Docker as a Disposable Test Environment
Docker is generally used for application development and deployment. While it is possible to develop and deploy Shiny applications in Docker containers, I have found it is much more useful to keep a Shiny Docker container that is a twin of my production server. This allows us to test new versions and new applications before putting them into production.
Why Not Use a VM?
There are articles written all over the internet about this, so I don’t want to rehash too much. From my perspective, the advantages of Docker as a test enviornment are:
-
Faster start time (way faster!)
-
Better performance. The ability to use system hardware instead of hardware abstraction.
-
Disposable. If we make a mistake, it’s much easier to delete the container and spin up a new one.
Why CentOS?
Most enterprise production enviornments, that I’m aware of, use either RHEL or CentOS. Many Docker containers for Shiny and R use a Debian OS. The differences are minimal, however they are different. It doesn’t seem logical to test in Debian and deploy in RHEL.
The Rocker Project
Carl Boettiger and Dirk Eddelbuettel maintain the rocker-org project, which hosts several Docker containers relating to the world of R. Many of these containers can be fired up in only a couple of minutes. I highly recommend checking it out.
Shiny on CentOS
The following walk-through uses a docker image from my GitHub repository. You can either do a git clone, or follow the link above and see the README
section.
This configuration includes:
-
R
-
RStudio Server
-
Shiny-Server
Additional R Packages include:
-
tidyverse
-
plotly
-
DT
Setup
-
Install Docker on your system.
-
Download or clone this repository.
Build the Dockerfile
View Your Docker Images
Run your Shiny-Server Docker image.
-
Shiny-Server is running at localhost:3838
-
RStudio Server is running at localhost:8787
-
The username and password for RStudio Server is
rstudio
.
Modify the Docker Container
This is a bare-bones container, so there is a good chance you will want to do some additional configuration. The command below will start your Docker instance and dump you into the root shell.
-
Arg -i tells docker to attach stdin to the container.
-
Arg -t tells docker to give us a pseudo-terminal.
-
Arg /bin/bash will run a terminal process in your container.
Install Additional Stuff
Maybe you need a PostgreSQL instance?
Exit the Container
Find the Container ID
Use Docker Commit to Save
The syntax is:
It should look something like this:
See New Container
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.