# Use a lightweight Python 3.11 image as the base. FROM python:3.11-slim # Update package lists, install curl, and run the Ollama installer script. # This downloads and installs Ollama, then cleans up the package lists. RUN apt-get update && apt-get install -y curl && \ curl -fsSL https://ollama.ai/install.sh | sh && \ apt-get clean && rm -rf /var/lib/apt/lists/* # Create a non-root user (named "user" with UID 1000) for better security. RUN useradd -m -u 1000 user # Switch to the newly created user. USER user # Set environment variables: ENV HOME=/home/user \ PATH="/home/user/.local/bin:$PATH" # Create directories for your application and logs. RUN mkdir -p $HOME/docker_ollama $HOME/logs # Set the working directory to the application directory. WORKDIR $HOME/docker_ollama # Copy the requirements.txt file into the container and install Python dependencies. COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --upgrade -r requirements.txt # Copy the rest of your application code into the container. COPY --chown=user . . # Ensure the start script has executable permissions. RUN chmod +x start.sh # Expose the necessary ports: EXPOSE 7860 11434 # Set the container's default command to run the start.sh script when the container launches. CMD ["./start.sh"]