abdullahalioo commited on
Commit
f6ba75c
·
verified ·
1 Parent(s): 3a6ecdf

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -21
Dockerfile CHANGED
@@ -1,39 +1,30 @@
1
- # Use NVIDIA CUDA base image
2
  FROM nvidia/cuda:12.1.1-base-ubuntu22.04
3
 
4
- # Install system dependencies
5
  RUN apt-get update && apt-get install -y \
6
  python3.10 \
7
  python3-pip \
 
8
  git \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
- # Create a non-root user and working directory
12
- RUN useradd -m appuser && \
13
- mkdir -p /app && \
14
- chown appuser:appuser /app
15
 
16
- # Set environment variables for Hugging Face cache
17
  ENV TRANSFORMERS_CACHE=/app/model_cache \
18
  HF_HOME=/app/huggingface \
19
  XDG_CACHE_HOME=/app/cache
20
 
21
- # Switch to non-root user
22
- USER appuser
23
  WORKDIR /app
24
 
25
- # Create cache directories
26
- RUN mkdir -p $TRANSFORMERS_CACHE $HF_HOME $XDG_CACHE_HOME
27
-
28
- # Install Python dependencies
29
- COPY --chown=appuser:appuser requirements.txt .
30
  RUN pip install --no-cache-dir -r requirements.txt
31
 
32
- # Copy application code
33
- COPY --chown=appuser:appuser . .
34
-
35
- # Expose port (7860 in your error, adjust if needed)
36
- EXPOSE 7860
37
 
38
- # Run FastAPI
39
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
  FROM nvidia/cuda:12.1.1-base-ubuntu22.04
2
 
3
+ # 1. Install system dependencies properly
4
  RUN apt-get update && apt-get install -y \
5
  python3.10 \
6
  python3-pip \
7
+ python3.10-venv \
8
  git \
9
  && rm -rf /var/lib/apt/lists/*
10
 
11
+ # 2. Create and activate virtual environment
12
+ RUN python3.10 -m venv /opt/venv
13
+ ENV PATH="/opt/venv/bin:$PATH"
 
14
 
15
+ # 3. Set cache directories (writable locations)
16
  ENV TRANSFORMERS_CACHE=/app/model_cache \
17
  HF_HOME=/app/huggingface \
18
  XDG_CACHE_HOME=/app/cache
19
 
 
 
20
  WORKDIR /app
21
 
22
+ # 4. Install requirements FIRST (better layer caching)
23
+ COPY requirements.txt .
 
 
 
24
  RUN pip install --no-cache-dir -r requirements.txt
25
 
26
+ # 5. Copy app code
27
+ COPY . .
 
 
 
28
 
29
+ # 6. Explicitly use the virtualenv's uvicorn
30
+ CMD ["/opt/venv/bin/uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]