imravi commited on
Commit
992e4ec
·
verified ·
1 Parent(s): e9c0f46

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +24 -3
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- # Use an official PyTorch image as a base (includes CUDA for GPU support if available)
2
  FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
3
 
4
  # Set the working directory inside the container
@@ -9,6 +9,21 @@ RUN apt-get update && apt-get install -y \
9
  build-essential \
10
  && rm -rf /var/lib/apt/lists/*
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Install Python dependencies
13
  RUN pip install --no-cache-dir \
14
  pandas \
@@ -27,11 +42,17 @@ RUN pip install --no-cache-dir \
27
  COPY plant_data_chunks_and_embeddings.csv /app/plant_data_chunks_and_embeddings.csv
28
  COPY main.py /app/main.py
29
 
 
 
 
 
 
 
30
  # Set the environment variable to point to the app directory
31
  ENV PYTHONPATH=/app
32
 
33
  # Expose the port the app will run on
34
- EXPOSE 8000
35
 
36
- # Command to run the app using Uvicorn (ASGI server for FastAPI)
37
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]
 
1
+ # Use an official PyTorch image as a base
2
  FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
3
 
4
  # Set the working directory inside the container
 
9
  build-essential \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
+ # Create a non-root user
13
+ RUN useradd -m -u 1000 appuser
14
+
15
+ # Create cache directories and set permissions
16
+ RUN mkdir -p /.cache/huggingface && \
17
+ mkdir -p /.cache/torch && \
18
+ mkdir -p /.cache/sentence_transformers && \
19
+ chown -R appuser:appuser /.cache && \
20
+ chmod -R 777 /.cache
21
+
22
+ # Set environment variables for cache locations
23
+ ENV TRANSFORMERS_CACHE="/.cache/huggingface"
24
+ ENV TORCH_HOME="/.cache/torch"
25
+ ENV SENTENCE_TRANSFORMERS_HOME="/.cache/sentence_transformers"
26
+
27
  # Install Python dependencies
28
  RUN pip install --no-cache-dir \
29
  pandas \
 
42
  COPY plant_data_chunks_and_embeddings.csv /app/plant_data_chunks_and_embeddings.csv
43
  COPY main.py /app/main.py
44
 
45
+ # Set proper permissions for the app directory
46
+ RUN chown -R appuser:appuser /app
47
+
48
+ # Switch to non-root user
49
+ USER appuser
50
+
51
  # Set the environment variable to point to the app directory
52
  ENV PYTHONPATH=/app
53
 
54
  # Expose the port the app will run on
55
+ EXPOSE 5000
56
 
57
+ # Command to run the app using Uvicorn
58
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5000"]