New Tool Radar

Local AI

How to Run LocalAI on a GPU with Docker and CUDA

Switch the LocalAI Compose file to the NVIDIA CUDA image and enable the GPU block so models run on the graphics card instead of the CPU.

Schematic diagram with three steps: edit the LocalAI compose file to use the CUDA image, enable the NVIDIA GPU block, and restart the container to check the GPU is used.

The default LocalAI Compose file runs the CPU image. On a machine with an NVIDIA GPU, switching to the CUDA image moves inference onto the card, which is much faster for larger models. The install docs give the change as two edits to docker-compose.yaml.

Edit the Compose file

  1. Change the image line to the tag for your hardware, for example localai/localai:latest-gpu-nvidia-cuda-12.
  2. Remove the # from the GPU block so the container can reserve the GPU. For NVIDIA, the block reserves all GPUs.
  3. Restart the container: docker compose up -d.

The NVIDIA block needs the NVIDIA Container Toolkit installed on the host — without it, Docker cannot hand the GPU to the container and the start fails. The docs’ hardware table also lists CUDA 13, AMD, and Intel image tags, so pick the tag that matches your card rather than copying the CUDA 12 example blindly.

Confirm the GPU is used

Open the LocalAI web interface and run a chat, then check the container log for GPU loading messages. If generation is no faster than CPU, the GPU block is probably still commented out, or the wrong image tag is in use — stop the container, re-check the two edits, and start it again.

Check What you should see If you do not see it
GPU image set image is a -gpu- tag, not latest You edited the wrong compose file, or the change was not saved
GPU block enabled The NVIDIA reserve block is uncommented The container starts but runs on CPU
Toolkit present The container starts without a GPU error Install the NVIDIA Container Toolkit on the host first

Expected result. We checked the LocalAI install docs for the GPU image tag change, the uncommented GPU block, and the NVIDIA Container Toolkit requirement, and the start page for the hardware image table. We did not run Docker or LocalAI, so the steps above are UNTESTED on this machine.

Limits

A GPU speeds up inference; it does not let a model larger than GPU memory load. The CPU image still works for small models and testing, so only switch when you have a compatible GPU and the toolkit installed.

Sources

Sources checked 2026-11-28.

See all