Skip to main content

Containerisation for reproducible ML deployments

Learning
Complete

Think of containerisation as giving your ML model a suitcase packed with everything it needs — no matter where it’s going.

One of the most effective ways to address the challenges of reproducibility and dependency management in ML deployment is through containerisation. In this section, you’ll explore how containerisation works, why it’s essential for consistent and reliable ML systems, and how tools like Docker make it easy to package your model and its dependencies into a portable, production-ready unit.

What is containerisation?

Containerisation is a method of packaging software so it can run consistently across different computing environments. A container includes the application code, runtime, system tools, libraries, and settings —everything needed to run the application in a portable, self-contained unit.

Skills Application illustration

This approach ensures that the application behaves the same way whether it’s running on a developer’s laptop, a cloud server, or inside a production environment.

Key benefits of containerisation in ML deployment:

  • Isolation: Each container runs in its own sandboxed environment. This reduces the risk of conflicts between different versions of libraries or Python environments that other models or applications use on the same system.
  • Portability: Containers are environment-agnostic. You can build your container once and run it anywhere — on a laptop, in a CI/CD pipeline, or on a Kubernetes cluster — without worrying about missing packages or version mismatches.
  • Consistency: Reproducibility is a common challenge in ML. With containers, the model and its dependencies are frozen at build time, so you can be confident that the same code and packages produce the same results, no matter where the model runs.

How containers solve reproducibility problems

Imagine you've trained a model using scikit-learn==1.3.1 and pandas==1.5.3. If someone else tries to run it in an environment with a different version of pandas, the model might fail or behave unpredictably.

A container eliminates this problem by ensuring the environment always uses those exact versions. This helps teams build ML systems that are reproducible and reliable — especially when models move across environments.

Why containerise ML models?

In ML, even small mismatches in library versions or runtime environments can lead to major deployment headaches. Unlike generic applications, ML systems rely on tightly coupled components — specific library versions, Python builds, and system dependencies.

Containerisation helps you package all of this together into a deployable unit. For ML teams, this means:

  • No more ‘it worked on my machine.’
  • Smooth handoffs between development and operations.
  • Predictable results when models are retrained or served.

Docker fundamentals for ML

Docker is the most widely used container platform and a powerful tool for making ML models reproducible and portable. In an ML workflow, Docker helps you bundle everything your model needs into a single image that behaves consistently across environments.

What is the Docker CLI?

The Docker CLI (command line interface) is the tool you’ll use in your terminal to interact with Docker. It lets you build images, run containers, and manage deployments, all with simple commands.

In this unit, you’ll use a few key commands, such as docker build and docker run, to package and test your ML model. You don’t need to know everything about Docker — just enough to confidently package your model and run it anywhere.

The Dockerfile

A Dockerfile is a text-based script that defines how to build a Docker image. It describes the base environment, dependencies, working directory, and startup command.

<g></g><defs><clipPath><rect width="24" height="24" fill="white"></rect></clipPath></defs>## Example Here’s an example of a simple Dockerfile for deploying a trained ML model:

FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY . .

CMD ["python", "predict.py"]

What these instructions do:

  • FROM python:3.12-slim Uses a lightweight version of Python 3.12 as the base environment. This ensures compatibility and reduces image size.

  • WORKDIR /app Sets the working directory inside the container to /app. All subsequent commands run from here.

  • COPY requirements.txt Copies the dependency list into the container.

  • RUN pip install -r requirements.txt Installs the specified Python packages exactly as needed for your model to function.

  • COPY . . Copies your project files (e.g., model, scripts, data) into the container.

  • CMD ["python", "predict.py"] Sets the default command to run when the container starts — in this case, a script to serve or test your trained model.

Packaging and running a model

Once your Dockerfile is ready, you’ll use the Docker CLI to package and run your model:

Build the Docker image and name it

docker build -t my-ml-model .

Run the container

docker run my-ml-model

This creates a reusable, portable image that includes your model, its dependencies, and the code to run it. You can now deploy this image on any system with Docker installed, whether it’s your laptop, a cloud server, or part of a production pipeline.

Orchestrating containers at scale

As ML systems grow, it’s common to have multiple containers running together — for example, one for the model, another for the API, and others for data pipelines or monitoring tools.

That’s where tools like Kubernetes come in. It’s a container orchestration platform that helps you:

  • Deploy containers across a cluster of machines.
  • Automatically scale resources up or down.
  • Monitor and restart failed containers.
  • Roll out updates without breaking the system.

Action item: Skillable lab — containerising and running an ML model

In this skills application, you will complete a hands-on lab guiding you through containerising a pre-trained ML model and serving it using Docker.

Important access information

Please set aside 30 uninterrupted minutes to complete the lab before opening it. Your lab attempt will expire after 30 minutes. While you are welcome to restart, please keep in mind that you are limited to a maximum of five attempts at the lab within 90 days from your initial attempt.

Complete the skills application

Launch this unit's Skillable lab: Containerising and running an ML model

Note: Clicking ‘Launch’ will open a new window and take you to Skillable's virtual lab environment. To use the lab, you will leave the Multiverse platform and will then need to create an account with Skillable. Skillable's Terms and Conditions and policies will apply to your use of its labs. Using the Skillable lab environment is highly encouraged to help you practise these concepts, but is completely optional. If you or your employer does not wish to proceed with Skillable, then do not click this link and simply continue your learning experience with Multiverse.

Context

Reproducibility and portability are critical for deploying ML models across environments. In this lab, you’ll gain hands-on experience packaging a pre-trained model into a Docker container. You’ll be provided with a linear regression model, aPython script that loads the model and makes predictions, and arequirements file.

You’ll create a Dockerfile, build an image, and run a container to verify it produces accurate results —mirroring the type of setup in common production ML systems.

Instructions and materials

To complete the skills application, you must:

Time

Set aside 30 minutes of uninterrupted time before beginning.

Accessing Skillable labs

If this is the first time you are accessing a Skillable lab through Multiverse, follow the registration instructions below.

Open the lab

Open the guided lab on Skillable: Containerising and running an ML model.

Log in

Log in with your Skillable account and launch the lab.

Accept the T&Cs

Accept Skillable's Terms and Conditions. As a reminder, if you or your employer do not wish to agree to the Skillable Terms and Conditions, then you should exit the lab, return to this page, and continue your learning experience on Multiverse.

Using the lab

When using Skillable, follow the step-by-step guidance embedded within the activity.

Completion

Once you have finished on Skillable, return to this page in your browser and complete your learning journey with Multiverse.