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.
dockerised-shiny/
├── Dockerfile
├── myapp
│ └── app.R
├── README.md
├── shiny-server.conf
└── shiny-server.sh
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 \
wget
# Download and install shiny server
RUN wget --no-verbose https://download3.rstudio.org/ubuntu-14.04/x86_64/VERSION -O "version.txt" && \
VERSION=$(cat version.txt) && \
wget --no-verbose "https://download3.rstudio.org/ubuntu-14.04/x86_64/shiny-server-$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 shiny-server.sh /usr/bin/shiny-server.sh
# Copy shiny app to Docker image
COPY /myapp /srv/shiny-server/myapp
# Expose desired port
EXPOSE 80
CMD ["/usr/bin/shiny-server.sh"]
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
docker images
docker ps -a
For individual containers add the container ID
$ docker rm
To remove all exited containers :
$ docker rm $(docker ps -a -q -f status=exited)
Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.
docker system prune -a
docker save -o ~/myapp.tar myapp
docker load -i myapp.tar
docker run myapp
https://hub.docker.com/r/rocker/shiny
https://www.docker.com/get-started
https://www.bjoern-hartmann.de/post/learn-how-to-dockerize-a-shinyapp-in-7-steps/