SharathReddy commited on
Commit
d9d7da7
·
verified ·
1 Parent(s): eb46234

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +14 -20
Dockerfile CHANGED
@@ -1,33 +1,27 @@
1
  # 1. Start with a stable base image
2
  FROM python:3.10.13-slim-bullseye
3
 
4
- # 2. Set the working directory
5
- WORKDIR /code
6
-
7
- # 3. Install git as the root user
8
  RUN apt-get update && apt-get install -y --no-install-recommends git && \
9
  apt-get clean && rm -rf /var/lib/apt/lists/*
10
 
11
- # 4. Copy requirements and application files
 
 
 
 
 
 
12
  COPY ./requirements.txt .
13
  COPY ./mine_diffs.py .
14
-
15
- # 5. Install Python dependencies
16
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
17
 
18
- # 6. Create and switch to the non-root user
19
- # This command creates the user AND their primary group
20
- RUN useradd --create-home --uid 1000 user
21
- USER user
22
 
23
- # 7. IMPORTANT: Re-set WORKDIR to the user's home and set permissions
24
- # This ensures we are working in a directory the user owns
25
- WORKDIR /home/user/code
26
- RUN chown -R user:user /home/user
27
-
28
- # 8. Copy files again to the new WORKDIR
29
- COPY ./requirements.txt .
30
- COPY ./mine_diffs.py .
31
 
32
- # 9. Set the command to automatically run the script
33
  CMD ["python", "mine_diffs.py"]
 
1
  # 1. Start with a stable base image
2
  FROM python:3.10.13-slim-bullseye
3
 
4
+ # 2. Install git as the root user
 
 
 
5
  RUN apt-get update && apt-get install -y --no-install-recommends git && \
6
  apt-get clean && rm -rf /var/lib/apt/lists/*
7
 
8
+ # 3. Create a non-root user for security
9
+ RUN useradd --create-home --shell /bin/bash --uid 1000 user
10
+
11
+ # 4. Set the working directory in the new user's home
12
+ WORKDIR /home/user/app
13
+
14
+ # 5. Copy files and install dependencies
15
  COPY ./requirements.txt .
16
  COPY ./mine_diffs.py .
 
 
17
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
18
 
19
+ # 6. Change ownership of the app directory to the non-root user.
20
+ # This is the critical step to grant write permissions.
21
+ RUN chown -R user:user /home/user/app
 
22
 
23
+ # 7. Switch to the non-root user
24
+ USER user
 
 
 
 
 
 
25
 
26
+ # 8. Run the script automatically on startup
27
  CMD ["python", "mine_diffs.py"]