---
title: How to Build a Llama.cpp Container Image
url: https://docs.vultr.com/how-to-build-a-llama-cpp-container-image
description: Learn step-by-step how to build a Llama.cpp container image for efficient deployment and scaling of large language models in containerized environments.
publish_date: 2024-04-24T16:25:00.525021Z
last_updated: 2026-04-15T00:00:00.077250Z
author: Humphrey Mpairwe
header_image: https://docs.vultr.com/public/doc-assets/1791/e805c601156d0cd9.png
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

## Introduction

Llama.cpp is a high-performance inference platform designed for Large Language Models (LLMs) like Llama, Falcon, and Mistral. It provides a streamlined development environment compatible with both CPU and GPU systems. This article explains how to set up and run Llama.cpp in Docker using the Vultr Container Registry.

## Prerequisites

Before you begin:

* Deploy an instance using [Vultr's GPU Marketplace App](https://www.vultr.com/marketplace/apps/vultr-gpu-stack)
* Access the server [using SSH](https://www.vultr.com/docs/how-to-use-ssh-with-vultr-servers/).
* Start the Docker service.

    ```console
    $ sudo systemctl start docker
    ```

* Add the non-root user to the Docker group. For example, `linuxuser`.

    ```console
    $ sudo usermod -aG docker linuxuser
    ```

* Switch to the user:

    ```console
    $ su - linuxuser
    ```

## Set Up the Server

1. Create a new directory to store your Llama.cpp project files.

    ```console
    $ mkdir llama-project
    ```

1. Switch to the directory.

    ```console
    $ cd llama-project
    ```

1. Clone the Llama.cpp project repository using Git.

    ```console
    $ git clone https://github.com/ggerganov/llama.cpp/
    ```

1. List files and verify that a new `llama.cpp` directory is available.

    ```console
    $ ls
    ```

    Output:

    ```
    llama.cpp
    ```

1. Switch to the `llama.cpp` project directory.

    ```console
    $ cd llama.cpp
    ```

1. List all hidden files and verify that a new `.devops` directory is available.

    ```console
    $ ls -a
    ```

    Output:

    ```
    ..                 cmake           convert.py                     flake.lock     ggml-common.h        ggml-metal.h      ggml-quantsh     .git                         llama.cpp        
    CMakeLists.txt  .devops    
    ```

    The `.devops` directory contains the following Dockerfile resources:

    * `main.Dockerfile`: Contains the build context for CPU systems.
    * `main-cuda.Dockerfile`: Contains the build context for GPU systems.

    Use the above resources in the next sections to build a CPU or GPU system container image.

## Build a Llama.cpp Container Image for CPU Systems

Follow the steps below to build a new Llama.cpp container image using `main.Dockerfile` that contains the required build context and installs all necessary dependency packages for CPU-based systems.

1. Copy the `main.Dockerfile` from the `.devops` directory to the main `llama.cpp` project directory.

    ```console
    $ cp .devops/main.Dockerfile .
    ```

1. Build a new container image using `main.Dockerfile` with all files in the project directory. Replace `llama-image` with your desired image name.

    ```console
    $ docker build -f main.Dockerfile -t llama-image .
    ```

1. View all Docker images on the server and verify that a new `llama-image` is available.

    ```console
    $ docker images
    ```

    Output:

    ```
    REPOSITORY                                  TAG       IMAGE ID       CREATED              SIZE
    llama-image                                 latest    f4fcb571a2f7   About a minute ago   80.1MB
    ```

## Build a Llama.cpp Container Image for GPU Systems

The Llama.cpp `main-cuda.Dockerfile` resource contains the build context for NVIDIA GPU systems that run the latest [CUDA driver](https://docs.vultr.com/understanding-nvidia-cuda-driver-and-libraries) packages. Follow the steps below to build a Llama container image compatible with GPU systems.

1. Copy `main-cuda.Dockerfile` to the Llama.cpp project directory.

    ```console
    $ cp .devops/main-cuda.Dockerfile .
    ```

1. Build a new container image `llama-gpu-image` using the `main-cuda.Dockerfile` with all files in the working project directory.

    ```console
    $ docker build -f main-cuda.Dockerfile -t llama-gpu-image .
    ```

1. View all Docker images on the server and verify that the new `llama-gpu-image` is available.

    ```console
    $ docker images
    ```

    Output:

    ```
    REPOSITORY                                  TAG       IMAGE ID       CREATED          SIZE
    llama-gpu-image                             latest    40421f1469cf   2 minutes ago    2.08GB
    ```

    To run the Llama.cpp GPU container image, verify that your target host includes the minimum or higher CUDA version referenced by the `ARG CUDA_VERSION=` directive within `main-cuda.Dockerfile`. Run the following command to verify the target CUDA version.

    ```console
    $ cat main-cuda.Dockerfile | grep CUDA_VERSION=
    ```

    Output:

    ```
    ARG CUDA_VERSION=12.3.1
    ```

## Upload the Llama.cpp Container Image to the Vultr Container Registry

1. Open the Vultr Console.
1. Click **Products** and select **Container Registry** on the main navigation menu.

    ![Manage a Vultr Container Registry](https://docs.vultr.com/public/doc-assets/1791/47bcdf178bdf7096.png)

1. Click your target Vultr Container Registry to open the management panel and view the registry access credentials.
1. Copy the **Registry URL** value, **Username**, and **API Key** to use when accessing the registry.

    ![Open the Vultr Container Registry](https://docs.vultr.com/public/doc-assets/1791/cedc6b7e3dbc6739.png)

1. Switch to your server terminal session and log in to your Vultr Container Registry. Replace `exampleregistry`, `exampleuser`, `registry-password` with your actual registry details.

    ```console
    $ docker login https://sjc.vultrcr.com/exampleregistry -u exampleuser -p registry-password
    ```

1. Tag the Llama.cpp container image with your desired Vultr Container Registry tag. For example, `sjc.vultrcr.com/exampleregistry/llama-gpu-image`.

    ```console
    $ docker tag llama-gpu-image sjc.vultrcr.com/exampleregistry/llama-gpu-image
    ```

1. View all Docker images on the server and verify that the new tagged image is available.

    ```console
    $ docker images
    ```

    Output:

    ```
    REPOSITORY                                  TAG       IMAGE ID       CREATED          SIZE
    sjc.vultrcr.com/exampleregistry/llama-gpu-image     latest    40421f1469cf   3 minutes ago    2.08GB
    llama-gpu-image                             latest    40421f1469cf   3 minutes ago    2.08GB
    ```

1. Push the tagged image to your Vultr Container Registry repository.

    ```console
    $ docker push sjc.vultrcr.com/exampleregistry/llama-gpu-image
    ```

1. Open your Vultr Container Registry management panel and click **Repositories** on the top navigation bar to verify that the new repository is available.

    ![View Vultr Container Registry Repositories](https://docs.vultr.com/public/doc-assets/1791/419fa89e8920296b.png)
