How to set up Ubuntu to run Docker, a Shiny Server container, with an existing Apache proxy server configuration. This setup will work for a low-volume application. It runs a single container, on a single host.
Install Docker on the host.
sudo apt install docker.io
We’ll use docker-compose, the network composition tool. Make a directory for the application:
mkdir shiny cd shiny
Next, create this file, docker-compose.yml:
version: '3' services: shiny: image: rocker/shiny restart: always networks: - shinyservers ports: - "3838:3838" volumes: - "/opt/docker/shiny/logs:/var/log/shiny-server" - "/opt/docker/shiny/mountpoints/apps:/srv/shiny-server" networks: shinyservers: driver: bridge ipam: driver: default config: - subnet: 172.16.240.0/24
Create the directories to save logs and host the apps:
mkdir -p /opt/docker/shiny/logs mkdir -p /opt/docker/shiny/mountpoints/apps
I like to use names in my configuration, so I added this line to /etc/hosts:
172.16.240.1 shinyservers
My installation is using Apache as a proxy server to connect to Docker containers via the Docker network. Apache runs the SSL/TLS certification. I had an existing virtual host for this domain, and wanted to mount the Shiny server into the /shiny/ path, so I added this line:
ProxyPass "/shiny/" "http://shinyservers:3838/"
I won’t go into the specifics of the proxy server setup. Nginx or most any other web server can work. Likewise, running ShinyProxy is an alternative, as well.
I settled on using Apache because I’m hosting WordPress, and some WordPress examples use Apache .htaccess hacks. So, the containers running WordPress are using Apache, and used it for the host’s proxy as well.
To start the container, go into the shiny/ directory and run this command:
docker-compose up -d
The -d option causes it to run in daemon mode. This also tells the Docker daemon to restart the container when the system reboots.
The first time you run this, Docker will take a minute to download the image.
This diagram shows the Apache proxy and Docker network and container arrangement:
Apache <-> shinyservers network (172.16.240.0) <-> shiny container (172.16.240.??)
As a final step, I add a symlink in my home directory, so I can get into the apps/ directory:
ln -s /opt/docker/shiny/mountpoints/apps shiny-apps
Also Read
https://github.com/rocker-org/shiny
https://www.dabbleofdevops.com/blog/deploy-rshiny-with-the-rocker-shiny-docker-image