Skip to content

How to Run llama.cpp in Docker (2026): CPU, CUDA, ROCm and Compose Guide

8–12 minutes
Woman at a photo editing desk holding a tablet with a LLAMA.CPP DOCKER card, hook run llama.cpp in Docker

Running llama.cpp in Docker is the fastest way to get a clean, repeatable local LLM server. You skip compilers, CUDA toolkits and build flags. You pull one official image, mount a folder of GGUF models and get an OpenAI-compatible API plus a built-in chat page.

This guide covers every step.

You will pick the right image tag for your GPU, run the server on CPU, NVIDIA, AMD, Intel or Vulkan, download models straight from Hugging Face, write a Docker Compose file, add an API key, and fix the errors people hit most.

Everything here follows the official llama.cpp Docker and server docs as of December 2026.

TL;DR

  • Image: ghcr.io/ggml-org/llama.cpp:server (CPU) or :server-cuda, :server-cuda13, :server-rocm, :server-vulkan, :server-intel.
  • NVIDIA run: docker run --gpus all -p 8080:8080 -v ~/models:/models ghcr.io/ggml-org/llama.cpp:server-cuda -m /models/model.gguf -ngl 99
  • Server images already listen on 0.0.0.0:8080 and have a /health healthcheck.
  • Any flag can also be set as an LLAMA_ARG_* environment variable, which is handy in Compose.
  • NVIDIA needs the NVIDIA Container Toolkit on the host.

Why Run llama.cpp in Docker

llama.cpp is the engine behind many local AI apps. You can install llama.cpp natively, but Docker has real advantages:

  • No build step. The project publishes ready images for CPU, CUDA 12, CUDA 13, ROCm, Vulkan, Intel SYCL, MUSA and OpenVINO.
  • Easy updates. Pull the new tag and restart the container.
  • Clean host. No CUDA toolkit or compiler on your machine, only the GPU driver.
  • Same setup everywhere. The Compose file you test on a laptop runs the same on a home server or cloud GPU.

If you only want a one-click desktop app, Ollama or LM Studio may suit you better. If you want the newest llama.cpp features and full control of every flag, Docker is the sweet spot.

Choose the Right Image Tag

All images live on GitHub Container Registry under ghcr.io/ggml-org/llama.cpp. There are three base types:

Type What it contains Use it for
server Only llama-server An API and web chat (most people)
light llama-cli and llama-completion Chatting or scripting in the terminal
full CLI tools plus model conversion and quantization tools Converting and quantizing models

Add a suffix for your hardware:

Hardware Server tag Platforms
CPU only server amd64, arm64, s390x
NVIDIA, CUDA 12 server-cuda amd64, arm64
NVIDIA, CUDA 13 server-cuda13 amd64, arm64
AMD ROCm server-rocm amd64
Vulkan (AMD, Intel, NVIDIA) server-vulkan amd64, arm64
Intel GPU (SYCL) server-intel amd64
Intel OpenVINO server-openvino amd64
Moore Threads server-musa amd64

The same suffixes work for light and full, for example light-cuda or full-rocm. The docs note that GPU images are built by CI but not tested beyond the build, so if one misbehaves, try the Vulkan image or build locally.

CUDA 12 or 13? Use server-cuda unless your driver is new enough for CUDA 13 and you want the newer toolkit. The CUDA 12 image is built on CUDA 12.8.1, which supports RTX 50-series cards.

Run the Server on CPU

Start with CPU to confirm the basics work. You need Docker installed and a GGUF model file. If you are new to model files, read GGUF quantization explained first; a Q4_K_M file is a good default.

  1. Make a models folder and put a GGUF file in it, for example ~/models/qwen3-4b-q4_k_m.gguf.
  2. Run the container:
    docker run -d --name llama \
      -p 8080:8080 \
      -v ~/models:/models \
      ghcr.io/ggml-org/llama.cpp:server \
      -m /models/qwen3-4b-q4_k_m.gguf -c 8192
  3. Watch it load: docker logs -f llama. Wait for the line saying the server is listening.
  4. Open the chat page at http://localhost:8080.

Everything after the image name is passed straight to llama-server, so any flag from the llama-server guide works here.

The server image already sets LLAMA_ARG_HOST=0.0.0.0 and LLAMA_ARG_PORT=8080, so you do not need --host or --port. That matters because a native llama-server build now listens on 127.0.0.1:9931 by default. Inside Docker you always get port 8080.

Run With an NVIDIA GPU

For NVIDIA cards, the container needs access to the GPU through the NVIDIA Container Toolkit.

  1. Install the NVIDIA driver on the host. Check it with nvidia-smi.
  2. Install the NVIDIA Container Toolkit from NVIDIA’s guide, then run sudo nvidia-ctk runtime configure --runtime=docker and restart Docker.
  3. Test GPU access: docker run --rm --gpus all ubuntu nvidia-smi should print your GPU.
  4. Start llama.cpp with all layers on the GPU:
    docker run -d --name llama --gpus all \
      -p 8080:8080 \
      -v ~/models:/models \
      ghcr.io/ggml-org/llama.cpp:server-cuda \
      -m /models/qwen3-14b-q4_k_m.gguf -c 16384 -ngl 99
  5. Confirm GPU use: the log lists your CUDA device, and nvidia-smi on the host shows memory in use.

-ngl sets how many layers go to VRAM. Recent builds default to auto and use a fit option that sizes layers and context to your free memory, but setting -ngl 99 makes the intent clear.

For two GPUs, add --tensor-split 1,1 or let llama.cpp split by free memory. For huge MoE models, see llama.cpp MoE offload.

On Windows, Docker Desktop with the WSL 2 backend passes NVIDIA GPUs through with the same --gpus all flag, as long as your Windows NVIDIA driver is current.

AMD, Intel and Vulkan GPUs

AMD with ROCm

ROCm containers need the GPU device files:

docker run -d --name llama \
  --device /dev/kfd --device /dev/dri \
  --group-add video \
  -p 8080:8080 -v ~/models:/models \
  ghcr.io/ggml-org/llama.cpp:server-rocm \
  -m /models/model.gguf -ngl 99

Vulkan

Vulkan works on AMD, Intel and many NVIDIA cards and is often the simplest route for consumer AMD GPUs. Pass /dev/dri:

docker run -d --name llama --device /dev/dri \
  -p 8080:8080 -v ~/models:/models \
  ghcr.io/ggml-org/llama.cpp:server-vulkan \
  -m /models/model.gguf -ngl 99

More on this backend in our llama.cpp Vulkan guide.

Intel GPUs (SYCL)

The official docs pass the render and card devices. List them with ls -la /dev/dri, then:

docker run -d --name llama \
  --device /dev/dri/renderD128:/dev/dri/renderD128 \
  --device /dev/dri/card0:/dev/dri/card0 \
  -p 8080:8080 -v ~/models:/models \
  ghcr.io/ggml-org/llama.cpp:server-intel \
  -m /models/model.gguf -ngl 99

Install the Intel GPU driver on the host. The docs say Intel Docker use is tested on native Linux, and WSL is not verified yet.

Download Models From Hugging Face

You do not have to download GGUF files by hand. The -hf flag pulls a model from Hugging Face on first start:

docker run -d --name llama --gpus all \
  -p 8080:8080 \
  -v ~/llama-cache:/cache -e LLAMA_CACHE=/cache \
  ghcr.io/ggml-org/llama.cpp:server-cuda \
  -hf ggml-org/gemma-3-4b-it-GGUF -ngl 99
  • Add :Q8_0 or another tag to pick a quant, as in -hf user/repo:Q8_0. Without a tag it picks Q4_K_M, or the first file if there is none.
  • Vision projector files (mmproj) download automatically when the repo has one.
  • LLAMA_CACHE points the download cache at a mounted folder, so models survive container restarts instead of downloading again.
  • For gated models, pass -e HF_TOKEN=your_token.
  • Add --offline later to force the cache and block network access.

Docker Compose Setup

Compose keeps your settings in one file. Every llama-server flag has an environment variable form (LLAMA_ARG_ plus the flag name), so you can configure it without a long command:

services:
  llama:
    image: ghcr.io/ggml-org/llama.cpp:server-cuda
    container_name: llama
    ports:
      - "8080:8080"
    volumes:
      - ./models:/models
    environment:
      LLAMA_ARG_MODEL: /models/qwen3-14b-q4_k_m.gguf
      LLAMA_ARG_CTX_SIZE: 16384
      LLAMA_ARG_N_GPU_LAYERS: 99
      LLAMA_ARG_N_PARALLEL: 2
      LLAMA_ARG_FLASH_ATTN: "on"
      LLAMA_API_KEY: change-me
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    restart: unless-stopped

Run docker compose up -d and check docker compose logs -f. Boolean variables accept true, 1, on or enabled.

The image has a built-in healthcheck that calls http://localhost:8080/health. It returns 503 while the model loads and 200 when ready, so docker ps shows healthy once you can send requests.

Want a chat UI too? Add an Open WebUI service and point it at http://llama:8080/v1. Our Open WebUI with llama.cpp guide walks through it.

Add an API Key and Test the API

Port 8080 is open to your network once published. Add a key so only your apps can use it:

  1. Set the key with --api-key mykey or -e LLAMA_API_KEY=mykey. Several keys can be comma separated.
  2. Bind to localhost only if no other machine needs access: -p 127.0.0.1:8080:8080.
  3. Test the health endpoint, which needs no key: curl http://localhost:8080/health.
  4. Send a chat request:
    curl http://localhost:8080/v1/chat/completions \
      -H "Authorization: Bearer mykey" \
      -H "Content-Type: application/json" \
      -d '{"messages":[{"role":"user","content":"Say hi in five words"}]}'

Any OpenAI SDK works by setting base_url to http://localhost:8080/v1. For structured replies, see llama.cpp function calling.

Run llama-cli in a Container

For a quick terminal chat, use the light image. Its default entrypoint is llama-cli:

docker run -it --rm --gpus all -v ~/models:/models \
  ghcr.io/ggml-org/llama.cpp:light-cuda \
  -m /models/model.gguf -ngl 99

For one-shot completions in scripts, switch the entrypoint: --entrypoint /app/llama-completion and pass -no-cnv -p "Your prompt" -n 256.

The full image includes conversion tools. To turn a Hugging Face model into GGUF, follow convert a model to GGUF and run those scripts inside the full image with your model folder mounted.

Build Your Own Image

Build locally when you need a different CUDA version or want to target only your GPU architecture for a smaller, faster image:

git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
docker build -t local/llama.cpp:server-cuda \
  --target server -f .devops/cuda.Dockerfile \
  --build-arg CUDA_VERSION=12.8.1 \
  --build-arg CUDA_DOCKER_ARCH=120 .

CUDA_DOCKER_ARCH=120 targets RTX 50-series Blackwell cards. The default builds for all supported architectures. Other Dockerfiles in .devops/ cover ROCm, Vulkan, Intel and MUSA, each with full, light and server targets.

Which Setup Should You Use?

Goal Recommended setup
Quick test on any PC server image, small Q4 model, CPU
Fast local API on an RTX card server-cuda with -ngl 99 and Compose
AMD Radeon on Linux server-vulkan first, server-rocm if supported
Chat UI for the family Compose with llama.cpp plus Open WebUI and an API key
Many models, swap on demand Router mode with --models-dir, or llama-swap

Troubleshooting

could not select device driver “” with capabilities: [[gpu]]

The NVIDIA Container Toolkit is missing or Docker was not restarted after configuring it. Install it, run nvidia-ctk runtime configure --runtime=docker and restart Docker.

The model runs on CPU even with a CUDA image

Check that you passed --gpus all and used a -cuda tag. Look in the log for the found CUDA devices line. If it is missing, the GPU is not visible inside the container.

failed to open GGUF file or file not found

The path after -m must be the path inside the container. If you mount ~/models:/models, use -m /models/file.gguf, not the host path.

Connection refused on localhost:8080

The model may still be loading; /health returns 503 until it is ready. Also check that you published the port with -p 8080:8080 and did not override --port.

Out of memory while loading

Lower -c, use a smaller quant, or reduce -ngl. KV cache quantization with -ctk q8_0 -ctv q8_0 also saves VRAM.

Models download again on every restart

Mount a cache folder and set LLAMA_CACHE to it, as shown in the Hugging Face section.

Still stuck? Compare with Ollama in Docker or Docker Model Runner, which wrap llama.cpp with simpler defaults.

FAQ

Is there an official llama.cpp Docker image?

Yes. The project publishes images at ghcr.io/ggml-org/llama.cpp with server, light and full tags for CPU and many GPU backends.

Which port does the llama.cpp Docker server use?

Port 8080. The server image sets LLAMA_ARG_PORT=8080 and listens on all interfaces inside the container.

Does llama.cpp Docker work with RTX 50-series GPUs?

Yes. The CUDA 12 image uses CUDA 12.8.1, and a CUDA 13 image is also available. Use a current NVIDIA driver.

Can I run llama.cpp Docker on Windows?

Yes, through Docker Desktop with the WSL 2 backend. NVIDIA GPUs pass through with --gpus all.

Can I use llama.cpp Docker on a Mac?

The images run on Apple silicon as arm64 Linux, but Docker on macOS cannot use the Metal GPU. For speed on a Mac, run llama.cpp natively.

How do I update the image?

Run docker pull ghcr.io/ggml-org/llama.cpp:server-cuda (or your tag), then recreate the container with docker compose up -d.

Is the llama.cpp server OpenAI compatible?

Yes. It serves /v1/chat/completions, /v1/completions, /v1/embeddings and more, so OpenAI SDKs and tools work by changing the base URL.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman at a photo editing desk holding a tablet with a LLAMA.CPP DOCKER card, hook run llama.cpp in Docker