-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docker performance improvements and reduce image size #1016
Conversation
- Change base image from python:3.11-slim to python:3.11-alpine in the builder stage - Use apk package manager instead of apt-get to install dependencies - Remove unnecessary sudo command - Use pip install --no-cache-dir instead of pip install - Add second stage in Dockerfile for final image - Copy dependencies and entrypoint script from builder stage to final stage Signed-off-by: Plamen Ivanov <paco.iwanow@gmail.com>
- add coding utf-8 declaration - use `find` command to patch permissions of generated files Signed-off-by: Plamen Ivanov <paco.iwanow@gmail.com>
Pretty sure this will break ARM compatibility |
Belay - that - compiles fine on my ARM. New size is less than 1/2 the original - nice!!! |
Thanks for this! Can you have a look at this too @TheoMcCabe ? |
I don't like the maxdepth. Why do we have that? Otherwise, do you see any risks with this PR @k1lgor ? |
Curious what was approx image size before this? :) |
@AntonOsika |
I may have spoken too soon. I only quickly ran but there are some problems with using alpine for those of us who use docker compose containers. AM I missing something? are other people succesfully running it all like this in their workflow?? |
@definitiontv Maybe share some error msg, so I will be able to find a solution. Those are the supported arch for |
Hi all, # Use a lightweight base image
FROM python:3.11-slim AS builder
# Install necessary system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends tk tcl gcc curl
# Set working directory
WORKDIR /app
# Copy source code and entrypoint script
COPY . .
COPY docker/entrypoint.sh ./entrypoint.sh
# Install dependencies and application in a virtual environment
RUN python -m venv /venv && /venv/bin/pip install --upgrade pip && /venv/bin/pip install .
# Final image
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Copy application and virtual environment from the builder stage
COPY --from=builder /app /app
COPY --from=builder /venv /venv
# Add the virtual environment to the PATH
ENV PATH="/venv/bin:$PATH"
# Set the entrypoint
ENTRYPOINT ["bash", "entrypoint.sh"] Please take a look and be more active on the PR @definitiontv @AntonOsika @ATheorell @TheoMcCabe |
Merging! |
If multiple users face issues with Alpine, we can easily switch back to Ubuntu with almost the same reduction in image size. |
@k1lgor it looks like something depends on arrow which doesn't have wheels for Alpine. It tries to build it unsuccesfully because it's missing dependencies like cmake, make, gcc and arrow libraries. Didn't get very far debugging the issue but went back to the ubuntu image which works fine with the current pip dependencies. Possibly related: apache/arrow#18036 |
I will take a look at this one. |
Hey @k1lgor - any updates or expected actions on this one? |
@viborc |
Info
Dockerfile
in multi-stage build - helps to build faster and reduces the image sizeTime for initial build:
entrypoint.sh
- it is more optimized and avoids unnecessary iterations