docker/docker-cuda/README.md
This directory contains Docker configuration files for running LLaMA Factory with NVIDIA GPU support.
Before running the Docker container with GPU support, you need to install the following packages:
Docker: The container runtime
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install docker.io
# Or install Docker Engine from the official repository:
# https://docs.docker.com/engine/install/
Docker Compose (if using the docker-compose method):
# Ubuntu/Debian
sudo apt-get install docker-compose
# Or install the latest version:
# https://docs.docker.com/compose/install/
NVIDIA Container Toolkit (required for GPU support):
# Add the NVIDIA GPG key and repository
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
# Install nvidia-container-toolkit
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
# Restart Docker to apply changes
sudo systemctl restart docker
Note: Without nvidia-container-toolkit, the Docker container will not be able to access your NVIDIA GPU.
After installation, verify that Docker can access your GPU:
sudo docker run --rm --gpus all nvidia/cuda:12.4.0-base-ubuntu22.04 nvidia-smi
If successful, you should see your GPU information displayed.
cd docker/docker-cuda/
docker compose up -d
docker compose exec llamafactory bash
# Build the image
docker build -f ./docker/docker-cuda/Dockerfile \
--build-arg PIP_INDEX=https://pypi.org/simple \
--build-arg EXTRAS=metrics \
-t llamafactory:latest .
# Run the container
docker run -dit --ipc=host --gpus=all \
-p 7860:7860 \
-p 8000:8000 \
--name llamafactory \
llamafactory:latest
# Enter the container
docker exec -it llamafactory bash
If your GPU is not detected inside the container:
nvidia-container-toolkit is installednvidia-smidocker run --rm --gpus all ubuntu nvidia-smiIf you get permission errors, ensure your user is in the docker group:
sudo usermod -aG docker $USER
# Log out and back in for changes to take effect