Running Shiny in a Docker container


Dean Marchiori


January 17, 2022

Basic minimal example for running shiny in Docker. It is assumed you have Docker installed.


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.

This directory structure can be cloned from my github repo

├── 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 \  
    libxml2-dev \  
    libssl-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:

This will run the docker image ‘myapp’ in a container (in detached mode) and expose post 80. It will name it ‘myapp’ and remove it when exited.

docker run --rm -p 80:80 --name myapp -d myapp


Some helpful commands

List Images

docker images 

List All Containers

docker ps -a

Remove Containers

For individual containers add the container ID

$ docker rm

To remove all exited containers :

$ docker rm $(docker ps -a -q -f status=exited)

System Prune

Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.

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