Skip to content

Chỉ dùng CPU

shell
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

GPU Nvidia

Cài đặt NVIDIA Container Toolkit.

Cài đặt bằng Apt

  1. Cấu hình kho lưu trữ

    shell
    curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey \
        | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
    curl -fsSL https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \
        | sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \
        | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
    sudo apt-get update
  2. Cài đặt các gói NVIDIA Container Toolkit

    shell
    sudo apt-get install -y nvidia-container-toolkit

Cài đặt bằng Yum hoặc Dnf

  1. Cấu hình kho lưu trữ

    shell
    curl -fsSL https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo \
        | sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo
  2. Cài đặt các gói NVIDIA Container Toolkit

    shell
    sudo yum install -y nvidia-container-toolkit

Cấu hình Docker để sử dụng trình điều khiển Nvidia

shell
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Khởi động container

shell
docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

Lưu ý

Nếu bạn đang chạy trên hệ thống NVIDIA JetPack, Ollama không thể tự động phát hiện phiên bản JetPack chính xác. Truyền biến môi trường JETSON_JETPACK=5 hoặc JETSON_JETPACK=6 vào container để chọn phiên bản 5 hoặc 6.

GPU AMD

Để chạy Ollama bằng Docker với GPU AMD, hãy sử dụng thẻ rocm và lệnh sau:

shell
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama:rocm

Hỗ trợ Vulkan

Vulkan được đóng gói sẵn trong hình ảnh ollama/ollama và được bật theo mặc định khi container có thể truy cập các thiết bị GPU.

shell
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

Sử dụng OLLAMA_VULKAN=0 để tắt Vulkan, hoặc GGML_VK_VISIBLE_DEVICES=<ids> để chọn các thiết bị Vulkan cụ thể.

Chạy mô hình cục bộ

Bây giờ bạn có thể chạy một mô hình:

shell
docker exec -it ollama ollama run llama3.2

Thử các mô hình khác nhau

Bạn có thể tìm thêm nhiều mô hình khác trên Thư viện Ollama.