如何将 Mistral 模型永久构建到 Ollama 中? Dockerfile

问题描述 投票:0回答:1

我想创建一个 Dockerfile,在其中我将运行内置 Mistral 模型的 Ollama。现在,我只实现了这一点:当我运行 Ollama 时,它会在一个 Dockerfile 中下载 Mistral(我首先使用 Docker compose,但最终设法使用一个 Dockerfile)。

我想知道,是否可以将 Mistral 模型永久内置到 Ollama 图像中?这是我当前的解决方案:

entrypint.sh

#!/bin/sh
/bin/ollama serve &

# Wait for the server to start
sleep 5

# Execute the curl command
curl -X POST -d '{"name": "mistral"}' http://127.0.0.1:11434/api/pull

# Wait indefinitely to keep the container running
tail -f /dev/null

ollama
图像(Dockerfile):

# Use a base image for the application service
FROM ollama/ollama:0.1.37

# Expose port 11434 (assuming the application listens on this port)
EXPOSE 11434

# Define a volume for storing Ollama data
VOLUME /root/.ollama

# Install curl (assuming it's not already installed in the base image)
RUN apt-get update && apt-get install -y curl
 
# Define volumes
VOLUME ollama_data

# Copy the entrypoint script into the image
COPY entrypoint.sh /usr/local/bin/entrypoint.sh

# Make the script executable
RUN chmod +x /usr/local/bin/entrypoint.sh

# Set the entrypoint to the script
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

它工作得很好,但它下载了 Mistral 模型。我只想在图像构建过程中下载一次。可以吗?

docker ollama mistral-7b
1个回答
0
投票

您可以下载 Mistral 模型并将其在镜像构建过程中存储在适当的位置(根目录)。

更新了

Dockerfile
将下载Mistral模型并将其存储在
/root/.ollama/models/
中,不需要每次容器启动时都下载。

# Use a base image for the application service
FROM ollama/ollama:0.1.37

# Expose port 11434 (assuming the application listens on this port)
EXPOSE 11434

# Install curl and jq (assuming they're not already installed in the base image)
RUN apt-get update && apt-get install -y curl jq

# Define a volume for storing Ollama data
VOLUME /root/.ollama

# Download the Mistral model during the build process
RUN mkdir -p /root/.ollama/models \
    && curl -X POST -d '{"name": "mistral"}' http://127.0.0.1:11434/api/pull \
    && mv $(curl -s http://127.0.0.1:11434/api/models | jq -r '.[].path') /root/.ollama/models/

# Copy the entrypoint script into the image
COPY entrypoint.sh /usr/local/bin/entrypoint.sh

# Make the script executable
RUN chmod +x /usr/local/bin/entrypoint.sh

# Set the entrypoint to the script
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
© www.soinside.com 2019 - 2024. All rights reserved.