Using PIE in Docker ################### :category: PHP :tags: pecl, pie, docker :date: 2025-10-09 20:51:00 +0300 As you may know, `PECL is now soft-deprecated and PIE is the recommended way to install exenetsions `__. .. _rfc: https://wiki.php.net/rfc/adopt_pie_deprecate_pecl The current PHP docker images do not package PIE executable. Luckily there is `an instruction in the doc `__ that says this: .. _doc: https://github.com/php/pie/blob/main/docs/usage.md .. code-block:: docker 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: .. _rabbithole.wwwdotorg.org: https://rabbithole.wwwdotorg.org/2021/03/02/1-avoiding-docker-add-copy-layers.html .. code-block:: docker 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.