Deploy ShinyApps with Azure and Docker

Azure Containers wallpaper

In this new post, I explain how to deploy in an Azure WebApp a ShinyApps created with RStudio using Azure DevOps as repository and Docker as container. I wrote another post about dockerize Shiny Apps with command line. You can find the source code of the ShinyProxy and the ShinyApp on GitHub.

For data scientists, ShinyApps offer the possibility to quickly create cute web applications also for prototyping. ShinyApps don’t have security integrated. So, we have to find another way to add a security layer to our Shiny applications.

So, we will use ShinyProxy to add a security layer. This makes the deployment a bit harder but we will take advantage of that. The pipeline in Azure DevOps for ShinyProxy will be similar to the pipeline for a ShinyApp. I will show in this post how to create a Docker container for ShinyProxy and ShinyProxy.

ShinyProxy is your favourite way to deploy Shiny apps in an enterprise context. It has built-in functionality for LDAP authentication and authorization, makes securing Shiny traffic (over TLS) a breeze and has no limits on concurrent usage of a Shiny app.

Why use ShinyProxy?

ShinyProxy uses one or more Docker images to serve the Shiny apps to end users. If you want to deploy your Shiny apps, you will therefore need to build your own Docker image for the app.

Such a Docker image will typically contain:

  • an R installation with
  • all R packages the Shiny app depends on (‘dependencies’) and
  • a folder which contains the ui.R and server.R for your Shiny app

Also, you have to consider to use ShinyProxy if you:

  • want to seamlessly deploy Shiny apps that were developed locally using the Shiny R package
  • need enterprise features but want to stay with open source
  • trust Java on the server side for running your Shiny apps
  • want to get all benefits offered by Docker-based technology

Introduction

Data science is a broad church. There are common themes, and most practitioners have a general interest in how to operationalise data science processes.

In my environment, the data scientists are using RStudio to analyse the data and then Shiny to create a dashboard to represent the data. Shiny is a framework to create web application based on the data manipulation with RStudio. The application is a bunch of files in R, some HTML and CSS for ShinyApps. All those files are in a repository in Azure DevOps. My goal is to publish a ShinyApp in an Azure WebApp. To publish an application with ShinyApps, I have to create a container.

In this containerisation primer I’ll be using Docker. Docker is an application that enables you to build, test and ship containerised applications from your PC or Mac. Visit Docker download page here. Other apps are available, but Docker is accessible, easy to install and is currently used by millions of developers.

Docker scales and provides resilience using orchestration capabilities such as Kubernetes. And it’s also relatively easy to move to the cloud, where it both scales and provides a mechanism for collaborating across many more people in a consistent fashion.

We won’t cover the basics of how to install Docker, as you can find details on how to do this online, either via the official Docker support site, or elsewhere.

Also, you already know the basics of what containers are, and how they differ from virtual machines (VMs).

Install Docker

First step in this long post is to install Docker. In the office website, there is a section for Getting started where you can download the version of Docker for your operating system. After the installation, you will restart your machine. For more details, you can visit my post “Start with Docker“.

Docker Desktop Installation - Deploy ShinyApps with Azure and Docker
Docker Desktop Installation

Then, I recommend to create an account in Docker to download containers from the hub.

So, to proper execute Docker containers, it is important to configure Docker Desktop properly. Ensure the following settings are checked as follows:

  • Expose daemon on tcp://localhost:2375 without TLS
  • Use the WSL 2 based engine
Docker Settings - Deploy ShinyApps with Azure and Docker
Docker Settings

So, this is the first step deploy ShinyApps with Azure and Docker. Now, we take a quick look to Azure.

Create an account on Azure

To replicate all steps of this article, you need an Azure account, which you can create here for free. While the account is free, Microsoft will charge for the services you use. With a new account, you will receive a budget for playing around with a number of services for the 12 months.

Beyond that, the easiest way forward is to have a pay-as-you-go account and pay for the services you need and when you need them. Azure will only charge you for the period you use the services. The basic version of the services I suggest here should cost you no more than 20 cent per day.

To get a sense of the costs, check out the Azure Price Calculator. When you create new resources on Azure, it is always a good idea to follow a naming convention; so, it will be easy to find and organize your resources.

So, to continue with our deploy of ShinyApps with Azure and Docker, we have to create a new resource in Azure called Azure Container Registry. Azure Container Registry is a private version of Docker hub.

What is Docker Hub?

Docker Hub is the world’s largest repository of container images with an array of content sources including container community developers, open-source projects and independent software vendors (ISV) building and distributing their code in containers. Users get access to free public repositories for storing and sharing images or can choose subscription plan for private repos.

What is Azure Container Registry?

Azure Container Registry allows you to build, store, and manage container images and artifacts in a private registry for all types of container deployments. Use Azure container registries with your existing container development and deployment pipelines. Use Azure Container Registry Tasks to build container images in Azure on-demand, or automate builds triggered by source code updates, updates to a container’s base image, or timers. More information on Microsoft documentation.

Create a Container Registry

Azure Container Registry is a managed Docker container registry service used for storing private Docker container images. This guide details creating an Azure Container Registry instance using the Azure CLI. Then, use Docker commands to push a container image into the registry, and finally pull and run the image from your registry.

First, I have to creare a Resource Group for the new Container Registry. I really recommend to follow a naming convention when you create your resources. So, you quickly identify your resources and everything about each resource.

From the Azure portal, add a new resource clicked on Create a resource in the home page. Then, search Resource Group.

Add a new resource in Azure Portal - Deploy ShinyApps with Azure and Docker
Add a new resource in Azure Portal
Search for a Resource Group to create- Deploy ShinyApps with Azure and Docker
Search for a Resource Group to create

Now, follow the wizard to create your new Resource Group.

You want you can use Azure CLI to create the Resource Group. Create a resource group with the az group create command. An Azure resource group is a logical container into which Azure resources are deployed and managed.

The following example creates a resource group named myResourceGroup in the eastus location.

az group create --name myResourceGroup --location eastus

Now, follow the same procedure to create a new Container Registry. The registry name must be unique within Azure, and contain 5-50 alphanumeric characters.

Create a new Container Registry on Azure - Deploy ShinyApps with Azure and Docker
Create a new Container Registry on Azure

As before, you can create the Container Registry via Azure CLI. In the following example, myContainerRegistry007 is used. Update this to a unique value.

az acr create --resource-group myResourceGroup \
  --name myContainerRegistry007 --sku Basic

In both cases, your Container Registry will be created and you have a name like:

mycontainerregistry007.azurecr.io

Authentication with service principals

You can use an Azure Active Directory (Azure AD) service principal to provide container image docker push and pull access to your container registry. By using a service principal, you can provide access to “headless” services and applications.

What is a service principal?

Azure AD service principals provide access to Azure resources within your subscription. You can think of a service principal as a user identity for a service, where “service” is any application, service, or platform that needs to access the resources. You can configure a service principal with access rights scoped only to those resources you specify. Then, configure your application or service to use the service principal’s credentials to access those resources.

In the context of Azure Container Registry, you can create an Azure AD service principal with pull, push and pull, or other permissions to your private registry in Azure. For a complete list, see Azure Container Registry roles and permissions.

Why use a service principal?

By using an Azure AD service principal, you can provide scoped access to your private container registry. Create different service principals for each of your applications or services, each with tailored access rights to your registry. And, because you can avoid sharing credentials between services and applications, you can rotate credentials or revoke access for only the service principal (and thus the application) you choose.

For example, configure your web application to use a service principal that provides it with image pull access only, while your build system uses a service principal that provides it with both push and pull access. If development of your application changes hands, you can rotate its service principal credentials without affecting the build system.

Create a service principal

To create a service principal with access to your container registry, run the following script in the Azure Cloud Shell or a local installation of the Azure CLI. The script is formatted for the Bash shell.

Before running the script, update the ACR_NAME variable with the name of your container registry. The SERVICE_PRINCIPAL_NAME value must be unique within your Azure Active Directory tenant. If you receive an “'https://acr-service-principal' already exists.” error, specify a different name for the service principal.

You can optionally modify the --role value in the az ad sp create-for-rbac command if you want to grant different permissions. For a complete list of roles, see ACR roles and permissions.

After you run the script, take note of the service principal’s ID and password. Once you have its credentials, you can configure your applications and services to authenticate to your container registry as the service principal.

#!/bin/bash

# Modify for your environment.
# ACR_NAME: The name of your Azure Container Registry
# SERVICE_PRINCIPAL_NAME: Must be unique within your AD tenant
ACR_NAME=<container-registry-name>
SERVICE_PRINCIPAL_NAME=acr-service-principal

# Obtain the full registry ID for subsequent command args
ACR_REGISTRY_ID=$(az acr show --name $ACR_NAME --query id --output tsv)

# Create the service principal with rights scoped to the registry.
# Default permissions are for docker pull access. Modify the '--role'
# argument value as desired:
# acrpull:     pull only
# acrpush:     push and pull
# owner:       push, pull, and assign roles
SP_PASSWD=$(az ad sp create-for-rbac --name https://$SERVICE_PRINCIPAL_NAME --scopes $ACR_REGISTRY_ID --role acrpull --query password --output tsv)
SP_APP_ID=$(az ad sp show --id https://$SERVICE_PRINCIPAL_NAME --query appId --output tsv)

# Output the service principal's credentials; use these in your services and
# applications to authenticate to the container registry.
echo "Service principal ID: $SP_APP_ID"
echo "Service principal password: $SP_PASSWD"

Now, we have our credentials to login to the Container Registry to pull or push containers. Save these credentials because we have to use them soon.

Create an Ubuntu’s virtual machine

Now, in the Resource Group we have created, we are going to add a new virtual machine for Ubuntu. Again, add a new resource and this time search for Ubuntu or click on the link in the Popular list.

Create a new Ubuntu's virtual machine on Azure - Deploy ShinyApps with Azure and Docker
Create a new Ubuntu’s virtual machine on Azure

So, you can follow the wizard to create the machine.

Create a virtual machine on Azure - Deploy ShinyApps with Azure and Docker
Create a virtual machine on Azure

Select the Resource Group and give a name to your new machine. In the process, you have to specify a virtual network name and if you want a public IP or not. As I said before, I really recommend you to use a naming convention to create all the resources. You have a full description and an Excel file to help you in my post.

The only important thing to remember is, at the end of the process, Azure will give you a SSH certificate (.pem). Save carefully this certificate because with it you will connect to your machine via SSH. Also, a user will be created by the wizard: this user is azureuser but you can change it.

Connect to your new Linux machine

After the installation of the new Linux machine, we can connect to it via SSH. It is possible to download the certificate and save on your local machine. Under Connect, you have the command to use in the Command Prompt or Windows Terminal to open a SSH connection.

SSH for the Ubuntu's virtual machine - Deploy ShinyApps with Azure and Docker
SSH for the Ubuntu’s virtual machine

Unfortunately, you can have some issue with the certificate. For example, if you don’t be the only user to have access to the file, you will receive an error such as bad permission.

Command Prompt with bad permission error for opening a SSH connection - Deploy ShinyApps with Azure and Docker
Command Prompt with bad permission error for opening a SSH connection

Then, I decided to follow another path, using RDP (Remote Desktop Protocol).

Install Docker

First thing to do in the new machine is to install Docker. In the Linux Terminal or in your SSH connection, update the local database of software to make sure you have got the latest revisions. Type:

sudo apt-get update

Allow the operation to complete. To install Docker on Ubuntu, in the terminal window enter the command:

sudo apt install docker.io

The Docker service needs to be setup to run at startup. To do so, type in each command followed by enter:

sudo systemctl start docker
sudo systemctl enable docker

Connect with RDP

I progress to deploy ShinyApps with Azure and Docker and for that I want to be able to connect to the Ubuntu’s virtual machine I have created.

So, I can run all the commands I need to have ShinyProxy and ShinyApp up and running.

Most Linux VMs in Azure do not have a desktop environment installed by default. Linux VMs are commonly managed using SSH connections rather than a desktop environment. There are various desktop environments in Linux that you can choose. Depending on your choice of desktop environment, it may consume one to 2 GB of disk space, and take 5 to 10 minutes to install and configure all the required packages.

The following example installs the lightweight xfce4 desktop environment on an Ubuntu 18.04 LTS VM. Commands for other distributions vary slightly (use yum to install on Red Hat Enterprise Linux and configure appropriate selinux rules, or use zypper to install on SUSE, for example).

First, SSH to your VM. The following example connects to the VM named myvm.westus.cloudapp.azure.com with the username of azureuser. Use your own values:

ssh azureuser@myvm.westus.cloudapp.azure.com

If you are using Windows and need more information on using SSH, see How to use SSH keys with Windows.

Next, install xfce using apt as follows:

sudo apt-get update
sudo apt-get -y install xfce4

Install and configure a remote desktop server

Now that you have a desktop environment installed, configure a remote desktop service to listen for incoming connections. xrdp is an open-source Remote Desktop Protocol (RDP) server that is available on most Linux distributions, and works well with xfce. Install xrdp on your Ubuntu VM as follows:

sudo apt-get -y install xrdp
sudo systemctl enable xrdp

Tell xrdp what desktop environment to use when you start your session. Configure xrdp to use xfce as your desktop environment as follows:

echo xfce4-session >~/.xsession

Restart the xrdp service for the changes to take effect as follows:

sudo service xrdp restart

Set a local user account password

If you created a password for your user account when you created your VM, skip this step. If you only use SSH key authentication and do not have a local account password set, specify a password before you use xrdp to log in to your VM. xrdp cannot accept SSH keys for authentication. The following example specifies a password for the user account azureuser:

sudo passwd azureuser

Configure inbound port rules in the virtual machine

The virtual machine I have created doesn’t allow any connection from the internet apart from SSH (port 22). So, if we want that our deploy of ShinyApps with Azure and Docker can be used from internet, I have to open some ports. The important ports for the current installation are:

  • 3389 for Remote Desktop
  • 8080 to open the ShinyProxy app

To add those ports, click on Network in the virtual machine page and then click on “Add inbound port rule“, as in the following image.

Configure inbound port rules in the Ubuntu's virtual machine - Deploy ShinyApps with Azure and Docker
Configure inbound port rules in the Ubuntu’s virtual machine

Then, I have to configure the ports I want to open. I have to add one port at each time. In the following image, I show how to add the port 3389. Follow the same procedure for the other port.

In the tile “Add inbound security rule“, it is enough to change:

  • Destination port ranges
  • Name of the rule. In my case I call the rule Port_portnumber_In. I specified In or Out to clarify in what direction the rule is working

Then, press Add.

Add inbound security rule - Deploy ShinyApps with Azure and Docker
Add inbound security rule

Connect with Remote Desktop

Now, it is time to connection to our new shiny Ubuntu’s virtual machine. Click on Connect on the left menu in the virtual machine page, then download the RDP file. You can see where this file is located in the following image.

Connect to the Ubuntu's virtual machine with RDP - Deploy ShinyApps with Azure and Docker
Connect to the Ubuntu’s virtual machine with RDP

So, you can open the file you have just downloaded. You will see the classic window to confirm that you want to connect to the machine. Also, you can check “Don’t ask me again for connections to this computer“. Click on the button Connect.

Remote Desktop Connection to the Ubuntu's virtual machine - Deploy ShinyApps with Azure and Docker
Remote Desktop Connection to the Ubuntu’s virtual machine

Then, click on Yes to accept to connect to the machine although the identity of the remote computer cannot be verified.

Remote Desktop Connection to the Ubuntu's virtual machine - Connection authorization - Deploy ShinyApps with Azure and Docker
Remote Desktop Connection to the Ubuntu’s virtual machine – Connection authorization

Finally, you have opened the remote desktop connection with the Ubuntu’s virtual machine.

In general, open your local remote desktop client and connect to the IP address or DNS name of your Linux VM. Enter the username and password for the user account on your VM as follows:

Remote Desktop Connection to Ubuntu's virtual machine - XRDP authentication - Deploy ShinyApps with Azure and Docker
Remote Desktop Connection to Ubuntu’s virtual machine – XRDP authentication

After authenticating, the xfce desktop environment will load and look similar to the following example:

Remote Desktop Connection to Ubuntu's virtual machine - Desktop - Deploy ShinyApps with Azure and Docker
Remote Desktop Connection to Ubuntu’s virtual machine – Desktop

If your local RDP client uses network level authentication (NLA), you may need to disable that connection setting. XRDP does not currently support NLA. You can also look at alternative RDP solutions that do support NLA, such as FreeRDP.

The goal of this post is how to deploy ShinyApps with Azure and Docker using Azure Container Repository and an Ubuntu’s virtual machine. Now, we have to talk how to create the pipeline for ShinyProxy and ShinyApps.

ShinyProxy pipeline

As I said at the beginning of this post, I’m going to use ShinyProxy to add a security layer to the ShinyApp. So, I will create a new repository in Azure DevOps for the ShinyProxy and add the necessary files for that.

Azure DevOps helps your organization and yourself to organize the activities of yourself and your team, manage the code and deploy it. I explained more about Azure DevOps and how an organization can adopt a new organization style in my post “Digital transformation scenario with Azure, Visual Studio and Git“.

So, in the home page of Azure DevOps (if you are not registered yet, doing, it is free up to 5 users), click on New Project and follow the wizard. Then, go to Repos and create a new repository. I have to create 2 repositories: one for ShinyProxy and one for ShinyApp.

Create a new repository for ShinyProxy - Deploy ShinyApps with Azure and Docker
Create a new repository for ShinyProxy

Clone your repository in your local machine. You have to install Git if you don’t have it.

Then, I’m going to create some files for the ShinyProxy. You can visit GitHub to have the full solution.

Docker file

First, the docker file. This file is quite a boilerplate and you find it in every documentation about Shiny Proxy. Remember to use as a convention, capital letter for the DOCKERFILE.

FROM openjdk:8-jre

RUN mkdir -p /opt/shinyproxy/
RUN wget https://www.shinyproxy.io/downloads/shinyproxy-2.4.3.jar -O /opt/shinyproxy/shinyproxy.jar
# Shinyproxy configuration file included in container
COPY application.yml /opt/shinyproxy/application.yml

WORKDIR /opt/shinyproxy/
CMD ["java", "-jar", "/opt/shinyproxy/shinyproxy.jar"]

Application.yml

The server configuration is mainly done in a file named application.yml. If the default values must be overridden, this can be done by adding a file application.yml in the same folder where you launch the shinyproxy-*.jar file and specify properties in the YAML format. The configuration has the following values:

proxy:
  title: Open Analytics Shiny Proxy
  port: 8080
  authentication: simple
  admin-groups: scientists
  # Example: 'simple' authentication configuration
  users:
  - name: jack
    password: password
    groups: scientists
  - name: jeff
    password: password
    groups: mathematicians

  docker:
      internal-networking: true
      # url setting needed FOR WINDOWS ONLY
      # url: https://host.docker.internal:2375

  specs:
  - id: 01_hello
    display-name: Hello Application
    description: Application which demonstrates the basics of a Shiny app
    container-cmd: ["R", "-e", "shinyproxy::run_01_hello()"]
    container-image: openanalytics/shinyproxy-demo
    container-network: sp-example-net
    access-groups: [scientists, mathematicians]
  - id: 06_tabsets
    container-cmd: ["R", "-e", "shinyproxy::run_06_tabsets()"]
    container-image: openanalytics/shinyproxy-demo
    container-network: sp-example-net
    access-groups: scientists
  - id: testapp2
    display-name: Test application from container
    description: Docker test application
    container-cmd: ["R", "-e", "shiny::runApp('/root/testApp')"]
    container-image: yourregistry.azurecr.io/shinyappimage
    container-network: sp-example-net
    access-groups: scientists

logging:
  file:
    shinyproxy.log

spring:
  servlet:
    multipart:
      max-file-size: 200MB
      max-request-size: 200MB

In this file, you can see I use an image container called openanalytics/shinyproxy-demo. This is a basic application for demo. I want to use this image to verify if the installation will work. I will pull this image later in the post.

Based on the ShinyProxy documentation, the simple authentication allows you to display a login page. The list of username and password is in the file under the users section.

The list of apps is in the app section. For each Shiny application, we have to specify its display-name and description. But what we really need to understand is the next options:

  • container-cmd: this is the command ShinyProxy has to execute to run the Shiny application.
  • container-image: the name of the image that contains the Shiny application we want to run
  • container-network: this is the internal Docker network between containers the ShinyProxy has to use to reach the other Shiny applications.

Later, the only image we have to run is the ShinyProxy. We mustn’t run the ShinyApps.

Create the pipeline

So, it is time to create the pipeline to deploy ShinyProxy and ShinyApps with Azure and Docker. First, click on Pipelines on the left menu in your repository in Azure DevOps. Then, on the right top corner click the blue New pipeline.

Then, I have to follow the wizard. In the first step called Connect, I’m going to choose Azure Repos Git for the list because my code is there.

Azure DevOps - Where is your code? - Deploy ShinyApps with Azure and Docker
Azure DevOps – Where is your code?

Then, next step is to select the repository where the code is. In my case, the code is in the shinyproxy-image.

Azure DevOps - Pipeline: select repository - Deploy ShinyApps with Azure and Docker
Azure DevOps – Pipeline: select repository

So, the important part. Select from the list Docker - Build and push an image to Azure Container Registry. There are 2 options for Docker in the list, choose the correct one.

Docker - Build and push an image to Azure Container Registry - Deploy ShinyApps with Azure and Docker
Docker – Build and push an image to Azure Container Registry

Now, after the click on the Docker option, a window is opened where you have to select your Azure subscription. If you don’t have one, you must create your subscription on Azure.

Azure DevOps - Pipeline: choose subscription - Deploy ShinyApps with Azure and Docker
Azure DevOps – Pipeline: choose subscription

Finally, last step. From the dropdown list select your container registry, that one we have created previously. In the window, the Image Name is prepopulated but you can change it. Then, specify the DOCKERFILE but the suggestion in the textbox is correct. Then, click Validate and configure.

Azure DevOps - Pipeline: docker options - Deploy ShinyApps with Azure and Docker
Azure DevOps – Pipeline: docker options

So, if the process is working, you have a new container in the Azure Container Registry.

Azure Container Registry with the new container - Deploy ShinyApps with Azure and Docker
Azure Container Registry with the new container

ShinyApp pipeline

Our post is how to deploy ShinyProxy and ShinyApps with Azure and Docker. We did a lot so far but we have something more to do.

The pipeline for creating a Docker for your ShintApp is the same as the ShinyProxy. Then, you can follow the same steps I described in the previous section.

In a ShinyApp there are some considerations. I have created a repository for my ShinyApp and the structure is simple:

  • Root of the project I have the DOCKERFILE and the Rprofile.site. The Rprofile.site is common to all the project and must be there. The purpose of this file is to tell to Shiny what port the application has to use. The content of this file is:
local({
   options(shiny.port = 3838, shiny.host = "0.0.0.0")
})
  • In the root of the project, I have also an app folder. In this folder I have the app.R and the www folder where I store css, fonts, images, js and more.
ShinyApp repository: folder structure - Deploy ShinyApps with Azure and Docker
ShinyApp repository: folder structure

Now, we have to talk about the DOCKERFILE. First, this is the file

FROM openanalytics/r-base

LABEL maintainer "Enrico Rossini <enrico.rossini.uk@live.com>"

ARG project=testApp

# install Debian dependencies for R
RUN apt-get update && apt-get install -y \
    sudo \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    libssl-dev \
    libssh2-1-dev \
    libxml2-dev \
    libgit2-dev 

# packages needed renv and install
RUN R -e "install.packages(c('renv', 'devtools'), repos='https://cloud.r-project.org'); renv::consent(provided = TRUE)"
RUN R -e "install.packages('shiny', repos='https://cran.rstudio.com')"
RUN R -e "install.packages('shinydashboard', repos='https://cran.rstudio.com')"
RUN R -e "install.packages('shinythemes', repos='https://cran.rstudio.com')"

# create root folder for app in container
RUN mkdir /root/${project}

# copy the app to the image
COPY app /root/${project}

COPY Rprofile.site /usr/lib/R/etc/
EXPOSE 3838

CMD ["R", "-e", "shiny::runApp('/root/testApp')"]

First, when Docker will build this container, it downloads the image openanalytics/r-base. Then, it updates the packages in the Linux system with apt-get update and install some applications.

So, in this image there is an instance of R. Then, we can use some R commands such as install.packages. Also, it creates a folder for the project and copy the content of the app folder in there. Important thing: remember to copy the Rprofile.site on the /usr/lib/R/etc/ folder.

The application will be exposed on port 3838 with EXPOSE 3838.

Now, create a new pipeline following the instruction I wrote in the previous section. At the end, you must have a new container in the Azure Container Registry with your app.

Run the all solution

We are a step closer to complete the deploy of ShinyProxy and ShinyApps with Azure and Docker!

So, open your remote connection with your Ubuntu’s virtual machine. Open terminal. I recommend to install Hyper terminal because it allows you to copy and paste the image Id or paste your clipboard.

First of all, I have to login in the Azure Container Registry from the Ubuntu machine. At the beginning of this post, I show you how to create a service principal and now it is the time to use it.

In a new terminal window, type the following command:

sudo docker login yourregistry.azurecr.io 
            --username yourusername 
            --password yourpassword

If you are not sure about the url of your repository, open the Azure portal, go to the Container registry and copy the Login server.

Azure Container Repository login server - Deploy ShinyApps with Azure and Docker
Azure Container Repository login server

The result of that is Login Succeeded.

Login Succeeded on Ubuntu for Azure Container Registry - Deploy ShinyApps with Azure and Docker
Login Succeeded on Ubuntu for Azure Container Registry

Now, download from your container registry the images for ShinyProxy and ShinyApps. This operation could take few minutes.

sudo docker pull yourregistry.azurecr.io/shinyproxyimage
Docker pulls the image from Azure Container Registry - Deploy ShinyApps with Azure and Docker
Docker pulls the image from Azure Container Registry

Now, we want to pull the Shiny application and the demo.

sudo docker pull yourregistry.azurecr.io/shinyappimage
sudo docker pull openanalytics/shinyproxy-demo

Next step is to create the internal Docker network. For that, in the terminal type:

sudo docker network create sp-example-net

If it worked, you can see a new network in Docker. To list the network, type:

sudo docker network ls

and you can see the new network.

Docker network - Deploy ShinyApps with Azure and Docker
Docker networtk

The final step is to run the ShinyProxy, type that:

sudo docker run -d -v /var/run/docker.sock:/var/run/docker.sock 
     --net sp-example-net -p 8080:8080 
     yourregistry.azurecr.io/shinyproxyimage

If you need more Docker command, visit this post.

Finally, open your browser in Ubuntu and type

http://127.0.0.1:8080

Your ShinyApp is up and running. If you click on the links, you have your ShinyApps!

Conclusion

Long post. Finally, we know how to deploy ShinyProxy and ShinyApps with Azure and Docker using an Azure Container Repository and an Ubuntu virtual machine!

You have all the source code on GitHub.

What do you think? Did I a good job? Please use the forum for comment, suggestion or questions.