Site icon R-bloggers

Shiny Server on Docker: CentOS 7 Edition

[This article was first published on - r, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
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:

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.

git clone https://github.com/keberwein/docker_shiny-server_centos7

This configuration includes:

Additional R Packages include:

Setup

  1. Install Docker on your system.

  2. Download or clone this repository.

Build the Dockerfile

docker build /YOUR_PATH_TO/docker_shiny-server_centos7 --tag="shiny-server"

View Your Docker Images

docker images

Run your Shiny-Server Docker image.

docker run -p 3838:3838 -p 8787:8787 shiny-server

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.

docker run -p 3838:3838 -p 8787:8787 -it shiny-server /bin/bash

Install Additional Stuff

Maybe you need a PostgreSQL instance?

yum install postgresql-devel -y

Exit the Container

exit

Find the Container ID

docker ps -a

Use Docker Commit to Save

The syntax is:

docker commit [CONTAINER ID] [REPOSITORY:TAG]

It should look something like this:

docker commit b59185b5ba4b docker-shiny:shiny-server-v2

See New Container

docker images

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

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.