rairo commited on
Commit
44d369e
·
verified ·
1 Parent(s): 2ffc4de

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -17
Dockerfile CHANGED
@@ -1,31 +1,32 @@
1
- FROM python:3.10
2
 
3
- ### Set up user with permissions
4
- # Set up a new user named "user" with user ID 1000
5
- RUN useradd -m -u 1000 user
 
 
6
 
7
- # Switch to the "user" user
8
- USER user
9
 
10
- # Set home to the user's home directory
11
  ENV HOME=/home/user \
12
  PATH=/home/user/.local/bin:$PATH
13
 
14
- # Set the working directory to the user's home directory
15
  WORKDIR $HOME/app
16
 
17
- # Copy the current directory contents into the container at $HOME/app setting the owner to the user
18
- COPY --chown=user . $HOME/app
 
19
 
20
- ### Set up app-specific content
21
- COPY requirements.txt requirements.txt
22
- RUN pip3 install -r requirements.txt
23
 
24
- COPY . .
 
25
 
26
- ### Update permissions for the app
27
- USER root
28
- RUN chmod 777 ~/app/*
29
  USER user
30
 
 
 
 
31
  CMD ["python", "main.py"]
 
1
+ FROM python:3.10-slim
2
 
3
+ # 1) Install system deps (Graphviz provides `dot`)
4
+ USER root
5
+ RUN apt-get update && apt-get install -y --no-install-recommends \
6
+ graphviz \
7
+ && rm -rf /var/lib/apt/lists/*
8
 
9
+ # 2) Create non-root user
10
+ RUN useradd -m -u 1000 user
11
 
 
12
  ENV HOME=/home/user \
13
  PATH=/home/user/.local/bin:$PATH
14
 
 
15
  WORKDIR $HOME/app
16
 
17
+ # 3) Copy only requirements first for better caching
18
+ COPY requirements.txt $HOME/app/requirements.txt
19
+ RUN pip3 install --no-cache-dir -r requirements.txt
20
 
21
+ # 4) Copy the rest of the app
22
+ COPY . $HOME/app
 
23
 
24
+ # 5) Fix ownership (no 777 needed)
25
+ RUN chown -R user:user $HOME/app
26
 
 
 
 
27
  USER user
28
 
29
+ # Optional: sanity check during build (remove later if you want)
30
+ # RUN which dot && dot -V
31
+
32
  CMD ["python", "main.py"]