anurag629 commited on
Commit
eb3ceb3
·
1 Parent(s): ba15bf5

updated docker file to reduce docker image size

Browse files
Files changed (1) hide show
  1. Dockerfile +25 -18
Dockerfile CHANGED
@@ -1,6 +1,7 @@
1
- FROM python:3.8.0
 
2
 
3
- # Install required packages as root
4
  RUN apt-get update && apt-get install -y --no-install-recommends \
5
  bzip2 \
6
  g++ \
@@ -12,29 +13,35 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
12
  wget \
13
  python3-tk \
14
  ffmpeg && \
15
- rm -rf /var/lib/apt/lists/*
16
-
17
- WORKDIR /code
18
-
19
- COPY ./requirements.txt /code/requirements.txt
20
-
21
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
22
 
 
23
  RUN useradd -m -u 1000 user
24
- USER user
 
25
  ENV HOME=/home/user \
26
- PATH=/home/user/.local/bin:$PATH
27
 
 
28
  WORKDIR $HOME/app
29
 
 
30
  COPY --chown=user . $HOME/app
31
 
32
- # Minimize image size with sudo command and give permission to user
33
- RUN (apt-get autoremove -y; \
34
- apt-get autoclean -y; \
35
- rm -rf /var/lib/apt/lists/*; \
36
- echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers; \
37
- chown -R user:user $HOME; \
38
- chmod -R 777 $HOME)
 
 
 
 
 
39
 
 
40
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Use a smaller base image
2
+ FROM python:3.8-slim
3
 
4
+ # Install required packages
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  bzip2 \
7
  g++ \
 
13
  wget \
14
  python3-tk \
15
  ffmpeg && \
16
+ apt-get clean && \
17
+ rm -rf /var/lib/apt/lists/* && \
18
+ rm -rf /tmp/*
 
 
 
 
19
 
20
+ # Create a non-root user
21
  RUN useradd -m -u 1000 user
22
+
23
+ # Set environment variables
24
  ENV HOME=/home/user \
25
+ PATH=/home/user/.local/bin:$PATH
26
 
27
+ # Set the working directory
28
  WORKDIR $HOME/app
29
 
30
+ # Copy the application code
31
  COPY --chown=user . $HOME/app
32
 
33
+ # Switch to the non-root user
34
+ USER user
35
+
36
+ # Install Python dependencies
37
+ COPY ./requirements.txt $HOME/app/
38
+ RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt
39
+
40
+ # Minimize image size
41
+ RUN rm -rf /root/.cache && \
42
+ rm -rf /var/cache/apt/archives/* && \
43
+ rm -rf /var/lib/apt/lists/* && \
44
+ chmod -R 777 $HOME
45
 
46
+ # Command to run the application
47
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]