Sofia Casadei commited on
Commit
9290d06
·
1 Parent(s): 2fffc78
Files changed (1) hide show
  1. Dockerfile +21 -22
Dockerfile CHANGED
@@ -1,29 +1,28 @@
1
- # Single stage build
2
- FROM python:3.10.12-slim-bookworm
3
 
4
- # Create user with ID 1000 (required by HF Spaces)
5
- RUN useradd -m -u 1000 user && \
6
- chown -R user /opt/venv
7
 
8
- # Switch to non-root user context (matches security requirements)
9
- USER user
10
- WORKDIR /app
11
 
12
- # Set home directory (aligns with doc's permission guidance)
13
- ENV HOME=/home/user \
14
- PATH=/home/user/.local/bin:$PATH \
15
- HF_HOME=/home/user/.cache/huggingface
 
16
 
17
- # Install dependencies with pip (same approach as doc's example)
18
- COPY --chown=user requirements.txt .
19
- RUN pip install --no-cache-dir --upgrade pip && \
20
- pip install --no-cache-dir -r requirements.txt
 
21
 
22
- # Copy application code (same pattern)
23
- COPY --chown=user . .
24
 
25
- # Expose correct port (matches doc's default 7860)
26
- EXPOSE 7860
27
 
28
- # Identical CMD to doc's FastAPI example
29
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use the official Python 3.9 image
2
+ FROM python:3.9
3
 
4
+ # Set the working directory to /code
5
+ WORKDIR /code
 
6
 
7
+ # Copy the current directory contents into the container at /code
8
+ COPY ./requirements.txt /code/requirements.txt
 
9
 
10
+ # Install requirements.txt
11
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ # Set up a new user named "user" with user ID 1000
14
+ RUN useradd -m -u 1000 user
15
 
16
+ # Switch to the "user" user
17
+ USER user
18
+ # Set home to the user's home directory
19
+ ENV HOME=/home/user \
20
+ PATH=/home/user/.local/bin:$PATH
21
 
22
+ # Set the working directory to the user's home directory
23
+ WORKDIR $HOME/app
24
 
25
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
26
+ COPY --chown=user . $HOME/app
27
 
28
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]