Baha Joe commited on
Commit
3ec258f
·
1 Parent(s): 326f9c7

Final Docker fix: Added PATH and --user flag for pip install to resolve ModuleNotFoundError

Browse files
Files changed (1) hide show
  1. Dockerfile +11 -7
Dockerfile CHANGED
@@ -1,9 +1,10 @@
1
- # Use a lighter PyTorch image to save space and time
2
  FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
3
 
4
  ENV PYTHONUNBUFFERED=1
 
5
 
6
- # Install system dependencies
7
  RUN apt-get update && apt-get install -y --no-install-recommends \
8
  ffmpeg \
9
  libsm6 \
@@ -17,17 +18,20 @@ WORKDIR /home/user/app
17
  # 1. Create the user
18
  RUN useradd -m user
19
 
20
- # 2. INSTALL DEPENDENCIES FIRST (as root)
 
21
  COPY requirements.txt .
22
- RUN pip install --no-cache-dir -r requirements.txt
23
 
24
  # 3. CREATE DIRECTORIES AND SET PERMISSIONS (as root)
25
- RUN mkdir -p downloads clips && chown -R user:user /home/user/app
 
26
 
27
- # 4. NOW SWITCH TO THE USER
28
  USER user
29
 
30
  # 5. COPY THE CODE
31
  COPY --chown=user:user . .
32
 
33
- CMD ["python3", "bot.py"]
 
 
1
+ # Use a robust base image with Python 3.11 for AI tasks
2
  FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
3
 
4
  ENV PYTHONUNBUFFERED=1
5
+ ENV PATH="/home/user/.local/bin:$PATH" # Set PATH to find locally installed binaries
6
 
7
+ # Install system dependencies (FFmpeg is required for moviepy)
8
  RUN apt-get update && apt-get install -y --no-install-recommends \
9
  ffmpeg \
10
  libsm6 \
 
18
  # 1. Create the user
19
  RUN useradd -m user
20
 
21
+ # 2. INSTALL DEPENDENCIES (using the safe --user flag and targeting the user's home)
22
+ # This prevents permission issues and ensures modules are accessible
23
  COPY requirements.txt .
24
+ RUN pip install --no-cache-dir --user -r requirements.txt
25
 
26
  # 3. CREATE DIRECTORIES AND SET PERMISSIONS (as root)
27
+ # The RUN commands run as root by default, so we create and change ownership
28
+ RUN mkdir -p downloads clips && chown -R user:user /home/user/app /home/user/.local
29
 
30
+ # 4. SWITCH TO THE LIMITED USER
31
  USER user
32
 
33
  # 5. COPY THE CODE
34
  COPY --chown=user:user . .
35
 
36
+ # 6. Run the application
37
+ CMD ["python3", "bot.py"]