File size: 1,090 Bytes
9d6fd1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c2d16b
9d6fd1a
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Use the official Python 3.9 image
FROM python:3.9

# Set the working directory
WORKDIR /code

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl \
    git \
    && rm -rf /var/lib/apt/lists/*

# Install Ollama
RUN curl -fsSL https://ollama.ai/install.sh | sh

# Copy requirements and install dependencies
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# Set up a new user named "user" with user ID 1000
RUN useradd -m -u 1000 user

# Switch to the "user" user
USER user

# Set environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    OLLAMA_HOME="/tmp/ollama_cache"

# Set working directory
WORKDIR $HOME/app

# Copy application files
COPY --chown=user . $HOME/app

# Ensure Ollama has a cache directory
RUN mkdir -p /tmp/ollama_cache

# Start Ollama in the background and pull the model
RUN ollama serve > /tmp/ollama.log 2>&1 & sleep 5 && ollama pull llama3.2

# Start Ollama and Gradio UI
CMD ollama serve > /tmp/ollama.log 2>&1 & sleep 5 && python app.py