[Python] can't figure out how to shrink docker image after pip install

Discussão em 'Python' iniciado por Stack, Janeiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have a docker file that looks like this:

    FROM python:3.12-slim

    RUN apt-get update \
    && apt-get install -y --no-install-recommends git \
    && apt-get purge -y --auto-remove \
    && rm -rf /var/lib/apt/lists/*

    RUN pip3 install --no-cache-dir --upgrade \
    pip poetry

    WORKDIR /app

    COPY requirements.txt .
    RUN pip install -r requirements.txt \
    && rm -rf /root/.cache/pip

    # ENV POETRY_VIRTUALENVS_CREATE=false

    # COPY pyproject.toml .
    # RUN poetry install

    COPY . .

    EXPOSE 8501

    ENV PYTHONUNBUFFERED=1

    CMD streamlit run ./app.py


    my requirements file looks like this:

    streamlit>=1.41.1
    vertexai>=1.71.1
    google==3.0.0
    google-genai>=0.6.0
    google-generativeai==0.8.4
    st_cookie==1.0.0
    extra-streamlit-components==0.1.71


    for some reason.... the pip install step results in increasing the docker image by 850mb! I've tried to use poetry as well to see if that helps and even when I just have one of the dependencies (any one of them), the docker file still increases by 600mb at least. Any thoughts on why that is and how I can reduce the size? Do I just need to manually go through something like pipdeptree and run pip uninstall of large packages?

    Continue reading...

Compartilhe esta Página