Dockerised Shiny - Running a shiny app with Docker

1 minute read


This is a basic, minimal example of deploying a shiny app with Docker. It is assumed you have Docker installed.

The easiest way to get started is to fork my repo which contains a skeleton to get started with.


Our directory contains a folder called myapp which contains our shiny app file and other supporting files.

At the top level we have our dockerfile and other config files. These should be modified accordingly.

├── Dockerfile
├── myapp
│   └── app.R
├── shiny-server.conf


This should be adapted as required.

# Using rocker/rver::version, update version as appropriate
FROM rocker/r-ver:3.5.0

# install dependencies
RUN apt-get update && apt-get install -y \
    sudo \
    gdebi-core \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \

# Download and install shiny server
RUN wget --no-verbose -O "version.txt" && \
    VERSION=$(cat version.txt)  && \
    wget --no-verbose "$VERSION-amd64.deb" -O ss-latest.deb && \
    gdebi -n ss-latest.deb && \
    rm -f version.txt ss-latest.deb && \
    . /etc/environment && \
    R -e "install.packages(c('shiny', 'rmarkdown'), repos='$MRAN')" && \
    cp -R /usr/local/lib/R/site-library/shiny/examples/* /srv/shiny-server/

# Copy configuration files into the Docker image
COPY shiny-server.conf  /etc/shiny-server/shiny-server.conf
COPY /usr/bin/

# Copy shiny app to Docker image
COPY /myapp /srv/shiny-server/myapp

# Expose desired port

CMD ["/usr/bin/"] 


To build the Docker image (called myapp)

$ docker build -t myapp .


To run a container based on our Docker image:

$ docker run --rm -p 80:80 myapp


Some helpful commands

List Images

docker images 

List All Containers

$ docker ps -a

System Prune

$ docker system prune -a

Save as tar-archive

$ docker save -o ~/myapp.tar myapp

Load and Run Archive

$ docker load -i myapp.tar
$ docker run myapp

More info and References