shiny2docker is an R package designed to streamline the
process of containerizing Shiny applications using Docker. This vignette
demonstrates how to generate a Dockerfile for your Shiny application,
customize it, and configure GitLab CI to build and deploy your Docker
image.
The main function, shiny2docker(), automates the
creation of a Dockerfile. It does the following:
renv.lock file to capture your R package
dependencies..dockerignore file to exclude unnecessary
files, reducing build time and image size.To generate a Dockerfile in your current directory, simply run:
Alternatively, you can specify custom paths for your Shiny
application, the renv.lock file, and the output
Dockerfile:
The shiny2docker() function returns an object of class
dockerfiler. This object can be further manipulated to add
custom instructions before writing the Dockerfile to disk. For example,
you may want to set an environment variable:
The package also provides the set_gitlab_ci() function,
which simplifies the process of configuring a GitLab CI pipeline. This
pipeline is designed to build your Docker image and push it to the
GitLab container registry.
library(shiny2docker)
# Copy the .gitlab-ci.yml file to the current directory
set_gitlab_ci()
# Or copy the file to a specific directory (e.g., your project folder)
set_gitlab_ci("my_project")Once the .gitlab-ci.yml file is in place, you can
integrate with GitLab CI/CD to automate the Docker image build and
deployment process.
shiny2docker simplifies containerizing Shiny
applications by automating Dockerfile creation and CI configuration. By
integrating with renv for dependency management and
providing a customizable dockerfiler object, it offers a
flexible workflow for deploying Shiny apps in containerized
environments.
For further details, please refer to the package documentation and visit the dockerfiler GitHub repository.