docker image size local vs fly launch size


I’m working on setting up some python apps using docker and i’m running into a weird issue. I’m building my docker images locally using a docker file and i see the image size as 684MB when i run docker ls.

However, when i run flyctl launch and build the image on a fly machine, it shows the image is significantly larger:
image size: 5.3 GB

This is a pretty simple docker file and i’ve tried using intermediate containers, etc but i’m not sure why the fly build is so much larger?
Am i missing something or any ideas on what i’m doing wrong?

here’s a multi-stage build i tried:

# Use a multi-stage build to minimize the size
# Start with a builder image
FROM python:3.9-slim as builder
WORKDIR /build
COPY requirements.txt .

# Install dependencies in a virtual environment to easily copy them later
RUN python -m venv /venv \
    && /venv/bin/pip install --upgrade pip \
    && /venv/bin/pip install -r requirements.txt

# Final stage: Use the slim version of Python image for the final image
FROM python:3.9-slim
COPY --from=builder /venv /venv

# Ensure scripts are run using the virtual environment
ENV PATH="/venv/bin:$PATH"

CMD ["python", "./"]

This seems to have resolved using a different dockerfile. Not sure why, the requirements.txt is pretty similar for both.