File size: 2,717 Bytes
c56ebec 3f3d4c1 c56ebec 3f3d4c1 c56ebec 67fb3d1 3f3d4c1 67fb3d1 3f3d4c1 67fb3d1 3f3d4c1 67fb3d1 3f3d4c1 67fb3d1 c56ebec 67fb3d1 3bfba6d 4cde9f3 67fb3d1 4cde9f3 67fb3d1 c56ebec 67fb3d1 c56ebec 3f3d4c1 67fb3d1 3f3d4c1 2e30346 c56ebec 67fb3d1 c56ebec 3f3d4c1 c56ebec 67fb3d1 c56ebec 02b066a e026944 c56ebec 67fb3d1 c56ebec 3f3d4c1 35ecc4f 4cde9f3 2e30346 4cde9f3 3f3d4c1 35ecc4f 3f3d4c1 67fb3d1 3f3d4c1 |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# ----------------------------------------------------------
# 1. Base Image
# ----------------------------------------------------------
FROM ubuntu:22.04
# Avoid interactive prompts during build
ENV DEBIAN_FRONTEND=noninteractive
# ----------------------------------------------------------
# 2. Install System Dependencies
# ----------------------------------------------------------
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
curl \
ca-certificates \
git \
build-essential \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/*
# ----------------------------------------------------------
# 3. Install Ollama as Root
# ----------------------------------------------------------
# Set OLLAMA_HOME to a writable directory
ENV OLLAMA_HOME=/ollama-data
RUN mkdir -p $OLLAMA_HOME && chmod 755 $OLLAMA_HOME
RUN curl -fsSL https://ollama.com/install.sh | bash
# ----------------------------------------------------------
# 4. Create a Non-Root User
# ----------------------------------------------------------
RUN useradd -m appuser
# ----------------------------------------------------------
# 5. Set Permissions for Ollama Directory
# ----------------------------------------------------------
RUN chown -R appuser:appuser $OLLAMA_HOME
# ----------------------------------------------------------
# 6. Set Working Directory for the Application
# ----------------------------------------------------------
WORKDIR /app
# ----------------------------------------------------------
# 7. Copy and Install Python Requirements
# ----------------------------------------------------------
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt
# ----------------------------------------------------------
# 8. Copy Application Files
# ----------------------------------------------------------
COPY app.py /app/app.py
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# ----------------------------------------------------------
# 9. Set Environment Variables and Expose Port
# ----------------------------------------------------------
ENV API_KEY=${API_KEY}
EXPOSE 7860
# ----------------------------------------------------------
# 10. Adjust Ownership of Application Directory
# ----------------------------------------------------------
RUN chown -R appuser:appuser /app
# ----------------------------------------------------------
# 11. Switch to Non-Root User
# ----------------------------------------------------------
USER appuser
# ----------------------------------------------------------
# 12. Define Entrypoint
# ----------------------------------------------------------
CMD ["/entrypoint.sh"]
|