Skip to content

Instantly share code, notes, and snippets.

@markuskreitzer
Last active January 11, 2024 16:11
Show Gist options
  • Save markuskreitzer/1e83cc3e52404f9edaaf38e90f17b7ae to your computer and use it in GitHub Desktop.
Save markuskreitzer/1e83cc3e52404f9edaaf38e90f17b7ae to your computer and use it in GitHub Desktop.
A docker-compose for running ollama with webui

Running Ollama on Docker Compose

Assuming you start with a vanilla Ubuntu, you need to install Nvidia stuff

Add Nvidia apt registries:

curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
  && curl -s -L 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
    

Install and configure docker to use Nvidia:

sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker

Create a directory to store ollama's model files. Make sure you have at least a few 100 Gb free on a fast drive:

mkdir -p ollama/ollama-data

Copy the docker-compose.yml file into the ollama/ directory you create.

cd ollama
docker compose up -d
version: '3.8'
services:
ollama:
# Uncomment below for GPU support
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
volumes:
- ${OLLAMA_DATA_DIR-./ollama-data}:/root/.ollama
# Uncomment below to expose Ollama API outside the container stack
# ports:
# - 11434:11434
container_name: ollama
pull_policy: always
tty: true
restart: unless-stopped
image: ollama/ollama:latest
ollama-webui:
image: ghcr.io/ollama-webui/ollama-webui:main
container_name: ollama-webui
depends_on:
- ollama
ports:
- 8080:8080
environment:
- "OLLAMA_API_BASE_URL=http://ollama:11434/api"
extra_hosts:
- host.docker.internal:host-gateway
restart: unless-stopped
#volumes:
# ollama: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment