Skip to content

Commit ef6cbeb

Browse files
thamudimbaraa
authored andcommitted
refactor: optimize docker image from 3G to 1.4G
add multi stage to the docker image replace python image with python slim
1 parent 5709268 commit ef6cbeb

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

.dockerignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
venv
2-
.git
3-
.github
4-
__pycache__
2+
.*
3+
*.md
4+
LICENSE
5+
__pycache__

Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
FROM python:3.10.6
1+
FROM python:3.10.6-slim AS builder
22

33
WORKDIR /app
44

55
RUN pip install --upgrade pip
6+
ADD requirements.txt /tmp
7+
RUN pip install -r /tmp/requirements.txt
8+
COPY . /app
69

7-
ADD requirements.txt .
8-
RUN pip install -r requirements.txt
910

11+
# Run stage
12+
FROM python:3.10.6-slim
1013

11-
ADD . /app
14+
WORKDIR /app
15+
16+
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
17+
COPY --from=builder /usr/local/bin/ /usr/local/bin/
18+
COPY --from=builder /app .
19+
20+
ENTRYPOINT [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000" ]
1221

13-
ENTRYPOINT [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000" ]

0 commit comments

Comments
 (0)