how to install / pull Ollama models in Docker Container

I have created a chatbot application (based on python 3.10.10, langchain_community==0.2.5 and ollama LLM model, Ollama Embeddings model). I run this application on my local computer (which does not have a GPU), it is working fine.

But now, I want to run the model on server (which does not have any dependencies installed prior) therefore, I want to use Docker Image. Since I am using the Ollama, i have to use separate image of it. Therefore, I have decided to use docker-compose.yml file, where I have mentioned the Service of Ollama and Service of Chatbot. Apart from this, I have another service written is ollama-models-pull to pull the models of Ollama for LLM model and for Embeddings model.

I have my docker-compose.yml file as below:

services:
  ollama:
    container_name: ollama_v2
    image: ollama/ollama:latest
    restart: unless-stopped
    volumes:
      - "./ollamadata:/root/.ollama"   # Persist data and models
    ports:
      - "11434:11434"                  # Expose the Ollama service on port 11434
    healthcheck:
      test: ["CMD", "ollama", "list"]  # Check if Ollama is responding
      interval: 10s                    # Run the health check every 10 seconds
      timeout: 30s                     # Timeout for the health check is 30 seconds
      retries: 5                       # Retry 5 times before marking it as unhealthy
      start_period: 10s                # Wait 10 seconds before starting health checks
    networks:
      - ollama_network

  ollama-models-pull:
    container_name: ollama-models-pull
    image: curlimages/curl:latest       # Use curl to send HTTP requests
    depends_on:
      ollama:
        condition: service_healthy      # Wait for Ollama to be healthy
    command: >
      curl -X POST host.docker.internal:11434/api/pull -d '{"name":"mistral:latest"}'
      curl -X POST host.docker.internal:11434/api/pull -d '{"name":"nomic-embed-text"}'
    networks:
      - ollama_network

  chatbot:
    container_name: chatbot_v2
    build:
      context: ./    # The directory where Dockerfile and code are located
      dockerfile: Dockerfile
    restart: unless-stopped
    environment:
      - API_URL=host.docker.internal:11434     # Chatbot will access the Ollama API
    ports:
      - "8501:8501"                   # Expose chatbot on port 8080 (or any other port)
    depends_on:
      ollama-models-pull:
        condition: service_completed_successfully  # Wait for model pull to complete
    networks:
      - ollama_network

networks:
  ollama_network:
    driver: bridge

Problem: When I execute the docker-compose.yml file, it initialized three services as mentioned above. But after few seconds, the service ollama-models-pull gets exited for some reason by showing this message ollama-models-pull exited with code 0 .

Could you please share your knowledge about how to run Ollama inside the docker container, Pull the models of Ollama inside docker container and use them?

My end goal is to run the chatbot application to the machine where no dependencies is installed like in sever.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật