Using PIE in Docker

As you may know, PECL is now soft-deprecated and PIE is the recommended way to install exenetsions.

The current PHP docker images do not package PIE executable. Luckily there is an instruction in the doc that says this:

COPY --from=ghcr.io/php/pie:bin /pie /usr/bin/pie
RUN pie install asgrim/example-pie-extension

It works but this solution is bad. It will import a 6MB PIE executable as a dead weight. Trying to find a solution to this solution, I stumbled on this blog post: rabbithole.wwwdotorg.org. Luckily RUN --mount can work with external images instead of stages and files instead of directories. This allows us to collapse the installation into a single layer:

RUN --mount=type=bind,from=ghcr.io/php/pie:bin,source=/pie,target=/usr/local/bin/pie \
    pie install asgrim/example-pie-extension

This will make your final image 6MB ligher.

Comments

Comments powered by Disqus