I’m building a docker image for my python flask application from my mac.
However i noticed something strange : my linux/amd64 targeted images are 6x bigger.
From 1gb to 6gb image sizes.
I wonder how it’s possible?
i even doubted my Mac silicon and tried to build it from docker cloud / github but same result … the image is really 6 times bigger.
Here are my requirements
python-dotenv
pydantic
pydantic-settings
pinecone
langchain
langchain-pinecone
langchain-openai
langchain-huggingface
langserve
langgraph
fastapi
uvicorn
sse_starlette
and my docker file
# Stage 1: Builder
FROM python:3.11-slim AS compile-image
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Copy requirements first for better cache utilization
COPY ./chatbot/chatbot_requirements.txt .
# Create virtual environment and install dependencies
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --upgrade pip &&
pip install --no-cache-dir -r chatbot_requirements.txt &&
rm -rf /root/.cache/pip chatbot_requirements.txt
# Stage 2: Final
FROM python:3.11-slim AS runtime-image
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV PYTHONPATH="/app/:/app/chatbot/"
ENV PATH="/opt/venv/bin:$PATH"
# Create a non-root user
RUN useradd -m appuser
WORKDIR /app
# Copy the virtual environment from the builder stage
COPY --from=compile-image /opt/venv /opt/venv
# Copy application files
COPY --chown=appuser:appuser ./chatbot/ /app/chatbot/
COPY --chown=appuser:appuser .env .
# Switch to non-root user
USER appuser
EXPOSE 8000
CMD ["python", "chatbot/api/chatbot_endpoint.py"]
Do you have any idea why it’s like that and how could i fix it ?
Thank you