dembasowmr commited on
Commit
61044c2
·
1 Parent(s): df27f9e

Fix: Change ownership of /app to user in Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +11 -9
Dockerfile CHANGED
@@ -3,12 +3,11 @@
3
  # Use a base image with Python installed. Python 3.10 is fine.
4
  FROM python:3.10-slim-buster
5
 
6
- # Set the working directory inside the container
7
  WORKDIR /app
8
 
9
  # Install system dependencies needed for pdf2image (Poppler) and pytesseract (Tesseract)
10
  # These RUN commands need to be executed as root.
11
- # Added Arabic and French Tesseract language packs as per your request.
12
  RUN apt-get update && apt-get install -y \
13
  libpoppler-dev \
14
  tesseract-ocr \
@@ -16,22 +15,26 @@ RUN apt-get update && apt-get install -y \
16
  tesseract-ocr-tur \
17
  tesseract-ocr-ara \
18
  tesseract-ocr-fra \
19
- # Add other languages if needed
20
  && rm -rf /var/lib/apt/lists/*
21
 
22
- # Now, create the user and switch to it for non-root operations.
23
- # All subsequent commands (COPY, RUN for pip, CMD) will be executed as 'user'.
24
  RUN useradd -m -u 1000 user
 
 
 
 
 
 
25
  USER user
26
 
27
  # Set the Hugging Face cache directory to a path where the 'user' has write permissions.
28
  ENV HF_HOME=/app/huggingface_cache
29
 
30
- # Create the cache directory and ensure the 'user' owns it
31
- RUN mkdir -p $HF_HOME && chown user:user $HF_HOME
 
32
 
33
  # Copy requirements.txt and install Python dependencies
34
- # Ensure the user has ownership of copied files.
35
  COPY --chown=user:user requirements.txt .
36
  RUN pip install --no-cache-dir -r requirements.txt
37
 
@@ -40,7 +43,6 @@ RUN rm -rf "${HF_HOME}/hub/tmp"
40
  RUN find "${HF_HOME}/hub/models--" -name "*.lock" -type f -delete || true
41
 
42
  # Copy the rest of your application code
43
- # Ensure the user has ownership of copied files.
44
  COPY --chown=user:user . /app
45
 
46
  # Set environment variables for Tesseract and potentially for Python's sqlite3 module
 
3
  # Use a base image with Python installed. Python 3.10 is fine.
4
  FROM python:3.10-slim-buster
5
 
6
+ # Set the working directory inside the container (created as root)
7
  WORKDIR /app
8
 
9
  # Install system dependencies needed for pdf2image (Poppler) and pytesseract (Tesseract)
10
  # These RUN commands need to be executed as root.
 
11
  RUN apt-get update && apt-get install -y \
12
  libpoppler-dev \
13
  tesseract-ocr \
 
15
  tesseract-ocr-tur \
16
  tesseract-ocr-ara \
17
  tesseract-ocr-fra \
 
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
+ # Create the user
 
21
  RUN useradd -m -u 1000 user
22
+
23
+ # IMPORTANT: Change ownership of the /app directory to the new 'user'
24
+ # This allows the 'user' to write files and create subdirectories within /app.
25
+ RUN chown -R user:user /app
26
+
27
+ # Switch to the non-root user. All subsequent commands (COPY, RUN for pip, CMD) will be executed as 'user'.
28
  USER user
29
 
30
  # Set the Hugging Face cache directory to a path where the 'user' has write permissions.
31
  ENV HF_HOME=/app/huggingface_cache
32
 
33
+ # Create the cache directory (now /app is owned by 'user', so this should work)
34
+ # The chown user:user $HF_HOME is technically redundant if /app is owned by user, but harmless.
35
+ RUN mkdir -p $HF_HOME # Removed chown here, as its handled by /app ownership.
36
 
37
  # Copy requirements.txt and install Python dependencies
 
38
  COPY --chown=user:user requirements.txt .
39
  RUN pip install --no-cache-dir -r requirements.txt
40
 
 
43
  RUN find "${HF_HOME}/hub/models--" -name "*.lock" -type f -delete || true
44
 
45
  # Copy the rest of your application code
 
46
  COPY --chown=user:user . /app
47
 
48
  # Set environment variables for Tesseract and potentially for Python's sqlite3 module