本地1panel安装ollama

本文最后更新于 2024年6月11日。

直接从应用商店搜索ollama找到应用开始安装。
为了避免跨域无法被其他应用访问,勾选“端口外部访问”选项,另外勾选“编辑compose文件”
然后增加环境变量选项。

services:
  ollama:
    image: ollama/ollama:0.1.39
    container_name: ${CONTAINER_NAME}
    restart: unless-stopped
    ports:
      - ${PANEL_APP_PORT_HTTP}:11434
    networks:
      - 1panel-network
    tty: true
    volumes:
      - ./data:/root/.ollama
    labels:
      createdBy: "Apps"
networks:
  1panel-network:
    external: true

修改后

services:
  ollama:
    image: ollama/ollama:0.1.39
    container_name: ${CONTAINER_NAME}
    restart: unless-stopped
    environment:
      - OLLAMA_ORIGINS=app://obsidian.md*
    ports:
      - ${PANEL_APP_PORT_HTTP}:11434
    networks:
      - 1panel-network
    tty: true
    volumes:
      - ./data:/root/.ollama
    labels:
      createdBy: "Apps"
networks:
  1panel-network:
    external: true

然后确定运行等安装完成。
安装完成后本地访问wsl的IP地址加上11434端口或者http://127.0.0.1:11434/或者(也就是访问1panel所用IP,例如http://172.29.206.19:11434/)能看到“Ollama is running”表明安装成功了。

进入ollama容器的终端可以执行ollama相关命令

# ollama
Usage:
  ollama [flags]
  ollama [command]

Available Commands:
  serve       Start ollama
  create      Create a model from a Modelfile
  show        Show information for a model
  run         Run a model
  pull        Pull a model from a registry
  push        Push a model to a registry
  list        List models
  ps          List running models
  cp          Copy a model
  rm          Remove a model
  help        Help about any command

Flags:
  -h, --help      help for ollama
  -v, --version   Show version information

Use "ollama [command] --help" for more information about a command.
# ollama list
NAME                    ID              SIZE    MODIFIED     
phi3:latest             a2c89ceaed85    2.3 GB  3 weeks ago 
qwen:7b                 2091ee8c8d8f    4.5 GB  3 weeks ago 
llava:latest            8dd30f6b0cb1    4.7 GB  5 weeks ago 
qwen:latest             d53d04290064    2.3 GB  5 weeks ago 
llama3:8b               a6990ed6be41    4.7 GB  6 weeks ago 
codellama:latest        8fdf8f752f6e    3.8 GB  2 months ago
mistral:latest          61e88e884507    4.1 GB  2 months ago
nomic-embed-text:latest 0a109f422b47    274 MB  2 months ago
gemma:latest            430ed3535049    5.2 GB  3 months ago
llama2:latest           78e26419b446    3.8 GB  3 months ago