sathishaiuse commited on
Commit
3a6cbfa
·
verified ·
1 Parent(s): 7390d24

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +36 -11
Dockerfile CHANGED
@@ -1,23 +1,48 @@
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
- # Install Python dependencies listed in requirements.txt
11
- RUN pip3 install -r requirements.txt
 
 
 
 
 
 
12
 
13
- RUN useradd -m -u 1000 user
14
  USER user
15
  ENV HOME=/home/user \
16
- PATH=/home/user/.local/bin:$PATH
17
 
 
18
  WORKDIR $HOME/app
19
 
20
- COPY --chown=user . $HOME/app
 
 
 
 
 
21
 
22
- # Define the command to run the Streamlit app on port "8501" and make it accessible externally
23
  CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
 
1
+ # Use minimal Python 3.9 base (keeps with your requirement)
2
+ FROM python:3.9-slim
3
+
4
+ # set a consistent locale (optional but sometimes avoids warnings)
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
 
 
7
  WORKDIR /app
8
 
9
+ # Install minimal system deps needed for building some packages (xgboost sometimes needs libgomp)
10
+ # If you know you don't need build tools, you can remove build-essential.
11
+ RUN apt-get update && \
12
+ apt-get install -y --no-install-recommends \
13
+ build-essential \
14
+ libgomp1 \
15
+ ca-certificates \
16
+ && rm -rf /var/lib/apt/lists/*
17
+
18
+ # Copy project files first to leverage Docker cache for pip installs when requirements don't change
19
+ COPY . /app
20
+
21
+ # Upgrade pip & setuptools first (important for picking up newer wheels)
22
+ RUN python -m pip install --upgrade pip setuptools wheel
23
 
24
+ # Install Python deps (use the Python 3.9 compatible requirements file)
25
+ # Use --no-cache-dir to keep image small
26
+ RUN pip install --no-cache-dir -r requirements-py39.txt
27
+
28
+ # Create an unprivileged user and move app into their home with ownership
29
+ RUN useradd -m -u 1000 user \
30
+ && mkdir -p /home/user/app \
31
+ && chown -R user:user /home/user/app /app
32
 
 
33
  USER user
34
  ENV HOME=/home/user \
35
+ PATH=/home/user/.local/bin:$PATH
36
 
37
+ # Use the home app directory for runtime; copy project into it using appropriate ownership already set
38
  WORKDIR $HOME/app
39
 
40
+ # Ensure the app files are available in the user's app dir (you may already have them in /app)
41
+ # If your COPY above already put files into /app and you want them in /home/user/app:
42
+ RUN cp -r /app/* $HOME/app/ || true
43
+
44
+ # Expose Streamlit port (optional metadata)
45
+ EXPOSE 8501
46
 
47
+ # Run streamlit (disable XSRF if you intentionally want that; be cautious in production)
48
  CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]