abdibrahem commited on
Commit
a1a2086
·
verified ·
1 Parent(s): 56623dc

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +56 -0
Dockerfile ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a base image with Python
2
+ FROM python:3.10
3
+
4
+ # Set the working directory
5
+ WORKDIR /app
6
+
7
+ # Create a non-root user
8
+ RUN useradd -m -u 1000 appuser
9
+
10
+ # Install system dependencies
11
+ RUN apt update && apt install -y curl && \
12
+ curl -fsSL https://ollama.ai/install.sh | sh
13
+
14
+ # Create .ollama directory and set permissions
15
+ RUN mkdir -p /home/appuser/.ollama && \
16
+ chown -R appuser:appuser /home/appuser/.ollama
17
+
18
+ # Install Python dependencies
19
+ COPY requirements.txt requirements.txt
20
+ RUN pip install --no-cache-dir -r requirements.txt
21
+
22
+ # Copy application files
23
+ COPY . .
24
+
25
+ # Create a more robust startup script
26
+ RUN echo '#!/bin/bash\n\
27
+ echo "Starting Ollama server..."\n\
28
+ ollama serve &\n\
29
+ \n\
30
+ # Wait for Ollama server to be ready\n\
31
+ until curl -s http://localhost:11434/api/tags >/dev/null; do\n\
32
+ echo "Waiting for Ollama server to be ready..."\n\
33
+ sleep 2\n\
34
+ done\n\
35
+ \n\
36
+ echo "Pulling Mistral model..."\n\
37
+ ollama pull mistral\n\
38
+ \n\
39
+ echo "Starting FastAPI application..."\n\
40
+ uvicorn main:app --host 0.0.0.0 --port 7860' > start.sh && \
41
+ chmod +x start.sh
42
+
43
+ # Set ownership of the application files
44
+ RUN chown -R appuser:appuser /app
45
+
46
+ # Switch to non-root user
47
+ USER appuser
48
+
49
+ # Expose the port FastAPI will run on
50
+ EXPOSE 7860
51
+
52
+ # Set the HOME environment variable
53
+ ENV HOME=/home/appuser
54
+
55
+ # Run the startup script
56
+ CMD ["./start.sh"]