Pushpak21 commited on
Commit
7db940a
·
verified ·
1 Parent(s): 647f264

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -13
Dockerfile CHANGED
@@ -1,24 +1,29 @@
1
- # Use a minimal base image with Python 3.9 installed
2
  FROM python:3.9
3
 
4
- # Set the working directory inside the container to /app
5
- WORKDIR /app
6
-
7
- # Copy all files from the current directory on the host to the container's /app directory
8
- COPY . .
9
 
10
- USER user
11
- ENV HOME=/home/user \
12
- PATH=/home/user/.local/bin:$PATH
13
 
14
- # Install Python dependencies listed in requirements.txt
15
- RUN pip3 install -r requirements.txt
 
16
 
 
17
  RUN useradd -m -u 1000 user
 
 
 
 
18
 
 
 
19
  WORKDIR $HOME/app
20
 
21
- COPY --chown=user . $HOME/app
 
22
 
23
- # Define the command to run the Streamlit app on port "8501" and make it accessible externally
24
  CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
 
1
+ # Use Python 3.9 base
2
  FROM python:3.9
3
 
4
+ ENV PYTHONDONTWRITEBYTECODE=1 \
5
+ PYTHONUNBUFFERED=1
 
 
 
6
 
7
+ # 1) Work as root (default)
8
+ WORKDIR /app
 
9
 
10
+ # 2) Copy only requirements first for better layer caching
11
+ COPY requirements.txt /app/requirements.txt
12
+ RUN pip3 install --no-cache-dir -r requirements.txt
13
 
14
+ # 3) Create the non-root user BEFORE switching to it
15
  RUN useradd -m -u 1000 user
16
+ ENV HOME=/home/user
17
+
18
+ # 4) Prepare user home and app dir, set ownership
19
+ RUN mkdir -p $HOME/app && chown -R user:user $HOME
20
 
21
+ # 5) Now switch to the non-root user
22
+ USER user
23
  WORKDIR $HOME/app
24
 
25
+ # 6) Copy the rest of the source as that user
26
+ COPY --chown=user:user . $HOME/app
27
 
28
+ # 7) Run your app
29
  CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]