Skip to main content
AI in Production 2026 is now open for talk proposals.
Share insights that help teams build, scale, and maintain stronger AI systems.
items
Menu
  • About
    • Overview 
    • Join Us  
    • Community 
    • Contact 
  • Training
    • Overview 
    • Course Catalogue 
    • Public Courses 
  • Posit
    • Overview 
    • License Resale 
    • Managed Services 
    • Health Check 
  • Data Science
    • Overview 
    • Visualisation & Dashboards 
    • Open-source Data Science 
    • Data Science as a Service 
    • Gallery 
  • Engineering
    • Overview 
    • Cloud Solutions 
    • Enterprise Applications 
  • Our Work
    • Blog 
    • Case Studies 
    • R Package Validation 
    • diffify  

Vetiver: Model Deployment

Author: Colin Gillespie

Published: June 20, 2024

tags: r, vetiver, machine-learning, production, mlops

This is Part 2 of a series of blogs on {vetiver}:

  • Part 1: Vetiver: First steps in MLOps
  • Part 2: Vetiver: Model Deployment (this post)
  • Part 3: Vetiver: Monitoring Models in Production
  • Part 4: Vetiver: MLOps for Python

Introduction

In our previous blog, we provided an overview of MLOps and the {vetiver} package, creating and deploying a simple model locally. In this post, we’ll show you how to deploy a model to production using Posit Connect, SageMaker, and Docker.

What is Docker

Docker is an open-source platform that allows developers to build, deploy, and run containers. These containers bundle application source code with the operating system libraries and dependencies needed to run that code.

Previously, we discussed deploying a Shiny Application using Docker. Similarly, we can deploy a set of APIs to access our model.

Data comes in all shapes and sizes. It can often be difficult to know where to start. Whatever your problem, Jumping Rivers can help.

Creating a Docker file

The {vetiver} package simplifies creating a Dockerfile. We simply run:

vetiver::vetiver_prepare_docker(
  pins::board_connect(), 
  "colin/k-nn", 
  docker_args = list(port = 8080)
)

This command accomplishes several tasks:

  • Uses the {renv} package to create a list of R package dependencies required to run your model.
  • Creates a file named plumber.R containing the necessary code to deploy an API, essentially just vetiver_api().
  • Generates the Dockerfile.

The Dockerfile includes several components. The first component sets the R version, specifies the package repository, and crucially, installs the necessary system libraries.

FROM rocker/r-ver:4.4.0
ENV RENV_CONFIG_REPOS_OVERRIDE https://packagemanager.rstudio.com/cran/latest

RUN apt-get update -qq && apt-get install -y --no-install-recommends \
  ...

The second component copies the renv.lock file and installs the required R packages:

COPY vetiver_renv.lock renv.lock
RUN Rscript -e "install.packages('renv')"
RUN Rscript -e "renv::restore()"

Finally, we have the plumber/API section

COPY plumber.R /opt/ml/plumber.R
EXPOSE 8080
ENTRYPOINT ["R", "-e", "pr <- plumber::plumb('/opt/ml/plumber.R'); pr$run(host = '0.0.0.0', port = 8080)"]

which runs the API on port 8080.

The container is built via

docker build --tag my-first-model .

The --tag flag allows you to name your Docker image. You can inspect your stored Docker images with:

docker image list                  
REPOSITORY       TAG       IMAGE ID       CREATED              SIZE
my-first-model   latest    792af21c775a   About a minute ago   1.33GB

To run the image, use

docker run --rm --publish 8080:8080 my-first-model

Posit Connect / Sage Maker

We can also trivially publish the model to Posit Connect via

vetiver::vetiver_deploy_rsconnect(board = pins::board_connect(), "colin/k-nn")

Similarly, we can publish to SageMaker using the function vetiver_deploy_sagemaker().


Jumping Rivers Logo

Recent Posts

  • Start 2026 Ahead of the Curve: Boost Your Career with Jumping Rivers Training 
  • Should I Use Figma Design for Dashboard Prototyping? 
  • Announcing AI in Production 2026: A New Conference for AI and ML Practitioners 
  • Elevate Your Skills and Boost Your Career – Free Jumping Rivers Webinar on 20th November! 
  • Get Involved in the Data Science Community at our Free Meetups 
  • Polars and Pandas - Working with the Data-Frame 
  • Highlights from Shiny in Production (2025) 
  • Elevate Your Data Skills with Jumping Rivers Training 
  • Creating a Python Package with Poetry for Beginners Part2 
  • What's new for Python in 2025? 

Top Tags

  • R (236) 
  • Rbloggers (182) 
  • Pybloggers (89) 
  • Python (89) 
  • Shiny (63) 
  • Events (26) 
  • Training (23) 
  • Machine Learning (22) 
  • Conferences (20) 
  • Tidyverse (17) 
  • Statistics (14) 
  • Packages (13) 

Authors

  • Amieroh Abrahams 
  • Shane Halloran 
  • Russ Hyde 
  • Myles Mitchell 
  • Tim Brock 
  • Theo Roe 
  • Colin Gillespie 
  • Aida Gjoka 
  • Gigi Kenneth 
  • Osheen MacOscar 
  • Sebastian Mellor 
  • Keith Newman 
  • Pedro Silva 

Keep Updated

Like data science? R? Python? Stan? Then you’ll love the Jumping Rivers newsletter. The perks of being part of the Jumping Rivers family are:

  • Be the first to know about our latest courses and conferences.
  • Get discounts on the latest courses.
  • Read news on the latest techniques with the Jumping Rivers blog.

We keep your data secure and will never share your details. By subscribing, you agree to our privacy policy.

Follow Us

  • GitHub
  • Bluesky
  • LinkedIn
  • YouTube
  • Eventbrite

Find Us

The Catalyst Newcastle Helix Newcastle, NE4 5TG
Get directions

Contact Us

  • hello@jumpingrivers.com
  • + 44(0) 191 432 4340

Newsletter

Sign up

Events

  • North East Data Scientists Meetup
  • Leeds Data Science Meetup
  • Shiny in Production
British Assessment Bureau, UKAS Certified logo for ISO 9001 - Quality management British Assessment Bureau, UKAS Certified logo for ISO 27001 - Information security management Cyber Essentials Certified Plus badge
  • Privacy Notice
  • |
  • Booking Terms

©2016 - present. Jumping Rivers Ltd