abishekcodes commited on
Commit
6a5544e
·
verified ·
1 Parent(s): c626dea

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -10
Dockerfile CHANGED
@@ -4,20 +4,31 @@ FROM python:3.9-slim
4
  # Set the working directory in the container
5
  WORKDIR /code
6
 
7
- # Copy the requirements file into the container at /code
8
- COPY ./requirements.txt /code/requirements.txt
 
 
9
 
10
- # Install any needed packages specified in requirements.txt
11
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
 
 
 
12
 
13
- # Copy the rest of the application's code into the container at /code
14
- COPY ./app /code/app
15
- COPY ./frontend /code/frontend
16
- COPY ./main.py /code/main.py
 
 
 
 
 
 
 
17
 
18
  # Expose the port the app runs on
19
  EXPOSE 8000
20
 
21
- # Define the command to run your app using uvicorn
22
- # This will start the FastAPI server
23
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
 
4
  # Set the working directory in the container
5
  WORKDIR /code
6
 
7
+ # ROOT CAUSE FIX: Create a non-root user and grant permissions.
8
+ # This is a best practice for security and avoids permission errors.
9
+ RUN useradd -m -u 1000 user
10
+ USER user
11
 
12
+ # Set environment variables for the new user
13
+ ENV HOME=/home/user
14
+ ENV PATH=/home/user/.local/bin:$PATH
15
+ # Crucially, tell transformers to use a local cache directory we own
16
+ ENV HF_HOME=/code/.cache
17
 
18
+ # Set the working directory again for the new user context
19
+ WORKDIR $HOME/app
20
+
21
+ # Copy the requirements file and install dependencies
22
+ COPY --chown=user ./requirements.txt $HOME/app/requirements.txt
23
+ RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt
24
+
25
+ # Copy the application code, ensuring the 'user' owns the files
26
+ COPY --chown=user ./app $HOME/app/app
27
+ COPY --chown=user ./frontend $HOME/app/frontend
28
+ COPY --chown=user ./main.py $HOME/app/main.py
29
 
30
  # Expose the port the app runs on
31
  EXPOSE 8000
32
 
33
+ # Define the command to run your app
 
34
  CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]