[Python] How to start ollama with docker compose with specific model

Discussão em 'Python' iniciado por Stack, Janeiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have a docker compose where a dummy python app is using ollama LMs on the background for some tasks. I want to be able to tell ollama somehow which model to download and use on the app deployment. Now my docker compose is like this:

    version: '3.8'

    services:
    elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
    container_name: elasticsearch
    environment:
    - discovery.type=single-node
    - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ports:
    - "9200:9200"
    volumes:
    - esdata:/usr/share/elasticsearch/data
    healthcheck:
    test: ["CMD-SHELL", "curl -f http://localhost:9200 || exit 1"]
    interval: 30s
    timeout: 10s
    retries: 5

    pokemon_app:
    build: .
    container_name: pokemon_app
    ports:
    - "8000:8000"
    depends_on:
    elasticsearch:
    condition: service_healthy
    ollama:
    condition: service_started
    environment:
    LLM_MODEL_NAME: ${LLM_MODEL_NAME}
    ELASTICSEARCH_URL: ${ELASTICSEARCH_URL}
    OLLAMA_URL: ${OLLAMA_URL}
    LOG_LEVEL: DEBUG
    healthcheck:
    test: ["CMD-SHELL", "curl -f http://localhost:8000/healthcheck || exit 1"]
    interval: 30s
    timeout: 10s
    retries: 5

    ollama:
    image: ollama/ollama:latest
    container_name: ollama
    volumes:
    - ollama:/root/.ollama
    ports:
    - "11434:11434"
    healthcheck:
    test: ["CMD-SHELL", "curl -f http://localhost:11434 || exit 1"]
    interval: 30s
    timeout: 10s
    retries: 5

    volumes:
    esdata:
    driver: local
    ollama:
    driver: local


    I have this env variable with the default LLM name that I use in my app:

    LLM_MODEL_NAME


    How can I make it so that by changing the value of this env variable I control which model ollama uses?

    Continue reading...

Compartilhe esta Página