做一个正常的image(958M):
FROM python:3.7 COPY . /app WORKDIR /app RUN pip install -r requirements.txt CMD ["gunicorn", "-w 4", "main:app"]
做一个小一点的image (139M):
FROM python:3.7-alpine COPY . /app WORKDIR /app RUN pip install -r requirements.txt CMD ["gunicorn", "-w 4", "main:app"]
使用docker 17.05版本的新特性:multi-stage build (https://docs.docker.com/develop/develop-images/multistage-build/) 来再减小一点image(去掉pip cache)
FROM python:3.7-alpine as base FROM base as builder RUN mkdir /install WORKDIR /install COPY requirements.txt /requirements.txt RUN pip install --install-option="--prefix=/install" -r /requirements.txt FROM base COPY --from=builder /install /usr/local COPY src /app WORKDIR /app CMD ["gunicorn", "-w 4", "main:app"]