In this article I talk about how to use “Docker Compose” to automate the deployment of an Apache Web server that gives access (via proxy) to Shiny applications and RStudio. A single command allows you to prepare the entire environment from scratch: the servers (Apache, Shiny and Rstudio) are downloaded, installed in isolation, and a private network is set up to let these applications communicate. Only dependency is to have Docker Compose installed on your computer.
This article is the continuation of the previous article where I explained the reasons and advantages of this configuration and how to do the manual installation and configuration. In this article I explain how to obtain a similar result with Docker technology, in a fully automated way with “Docker Compose”.
This is the sole command. Do you think you can do it? :-)
Docker and Docker Compose
What are they for?
Let’s start with the definition:
Docker is an open-source project that automates the deployment (delivery or release to the customer, with relative installation and commissioning or operation, of an application or software system typically within a corporate IT system) of applications inside software containers, providing an additional abstraction thanks to virtualization at the Linux operating system level. Wikipedia IT
Very briefly, let’s say it looks like a virtual machine dedicated to a single application. Imagine a docker container as composed of an executable, a portion of the file system containing the ecosystem needed by the application, a dedicated network interface. The container interacts with the environment via network connection or shared file system folders. The advantage of this configuration is that the applications in the containers do not depend on the software installed on the server, but they carry the dependencies. In this way, incompatibility problems are avoided: if the container works on one computer it will also work on the others. This allows you to use software without worrying about having the exact same environment installed, to make updates “by application”, and to rollback very easily.
Compose is an application that allows you to assemble a number of Docker containers and use them as a single service. A single configuration file describes how to configure them, connect them to each other via a virtual and dedicated network.
How are they used?
For convenience I have prepared a Git Repository with the configuration: https://github.com/rinproduction/docker-rweb/
The YAML file
docker-compose.yml contains the composition configuration:
The configuration file contains three services (three docker containers) and one network (
Apache is the web server used. The
apache docker image is denoted by
bitnami/apache:latest, which means that it is located at https://hub.docker.com/r/bitnami/apache and takes the latest version. At this address you will find the documentation of the Docker image. The
ports parameter indicates which ports to share with the world outside the Compose: in this case the ports are related to HTTP and HTTPS services. The http://localhost and https://localhost addresses work precisely because ports 80 and 443 are shared between Docker and the host (the computer).
volumes indicates how to share configuration files between the host and one of the containers.
environment is used to configure some environment variables used in the container.
The images containing the Shiny and RStudio applications are taken from https://hub.docker.com/r/rocker/. Here you will find a good number of updated and ready-to-use Docker images.
Note that in the
docker-compose.yml all containers are connected to the same subnet:
sp-net. This allows Apache when it receives a connection to forward it to Shiny or RStudio.
The next section contains a little guide on how to use this configuration in practice.
A computer with a Linux distribution on which Docker and Docker Compose is installed or can be installed. Note that compared to the article with the manual procedure, which asked that RStudio and Shiny Server be present and installed, here it is not required because the procedure also installs these piece of software.
Install Docker and Docker Compose
To install Docker use the specific instructions for the distribution you are using. I write here the instructions that I have tested on Ubuntu 20.04.
sudo apt install docker.io docker-compose
Download the configuration
To download the configuration you can use Git:
Note: I created a
rweb sub-folder because Compose uses it to create individual Docker instance labels - so rename it carefully if you have to.
If you don’t have git, download the repository from this address: https://github.com/rinproduction/docker-rweb/archive/main.zip.
Activate the configuration
Premise: you must have permissions to access the docker service to do this. So either your user belongs to the
docker group or you have to use administrative privileges (with
If you haven’t received any errors, the service is active!
Point your browser to:
- https://localhost/ to have confirmation of operation
- https://localhost/shiny to access Shiny Server
- https://localhost/rstudio to access RStudio Server (user: rstudio, password: rinproduction)
The code was written with the purpose of testing the possibility and ease of use of Docker Compose applied to our problem. In case you want to use it in production, depending on the situation, there may be other safety measures to be taken. Definitely you must regenerate the SSL key in the
config/ssl/ directory as the secret key is shared on a public repository (for the benefit of dissemination). Find out how to regenerate self-signed certificates here.
With this practice you get a system isolated from the main server, whose internal parts are well separated from each other, can be updated individually and are maximally reproducible: it means that, tested on one server, in principle they work on all the others.
Comment on Linkedin
Comment on Twitter