Multistage Dockerfile for small image

FROM python:3.7-slim-stretch AS builder

COPY . /app
WORKDIR /app

RUN apt-get update && apt-get install -y git python3-dev gcc
&& rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade -r requirements.txt

FROM python:3.7-slim
WORKDIR /app
COPY --from=builder /app/ /app/
ENV PORT 8080
CMD [ “python”, “app.py” ]

FROM python:3.7-slim-stretch AS builder

COPY . /app
WORKDIR /app

RUN apt-get update && apt-get install -y git python3-dev gcc
&& rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade -r requirements.txt

FROM python:3.7-slim-stretch
WORKDIR /app
COPY --from=builder /app/ /app/
ENV PORT 8080
CMD [ “python”, “app.py” ]