Skip to content

Commit

Permalink
Merge pull request #9 from pha123661:feat/docker-multi-stage-build
Browse files Browse the repository at this point in the history
Add multi stage build to optimize the image size
  • Loading branch information
pha123661 authored Feb 4, 2025
2 parents 560cdf1 + ac99b32 commit df9104d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3.8-slim-buster

# Builder stage: install dependencies and download resources
FROM python:3.8-slim-buster AS builder
WORKDIR /app

COPY requirements.txt /app/requirements.txt
Expand All @@ -8,8 +8,21 @@ RUN apt-get update && \
apt-get install --no-install-recommends --yes build-essential wget && \
pip install --no-cache-dir -r requirements.txt && \
python -m nltk.downloader punkt_tab && \
wget https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.ftz -O lid.176.ftz
wget https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.ftz -O lid.176.ftz && \
rm -rf /var/lib/apt/lists/*

# Final stage: copy only what is needed
FROM python:3.8-slim-buster
WORKDIR /app

# Copy installed Python packages (from the builder)
COPY --from=builder /usr/local/lib/python3.8/site-packages /usr/local/lib/python3.8/site-packages
# Copy downloaded file
COPY --from=builder /app/lid.176.ftz /app/lid.176.ftz
# Copy requirements if needed for reference (or omit if not necessary)
COPY --from=builder /app/requirements.txt /app/requirements.txt

# Copy application source code
COPY ./app/*.py /app

EXPOSE 8000
Expand Down

0 comments on commit df9104d

Please sign in to comment.