Docker: How to install PHP extension
13 October 2023 (Updated 13 October 2023)
Let’s suppose you wanted to install the PDO extension. Here’s how.
Create your custom Dockerfile:
FROM php:8.2-fpm
RUN docker-php-ext-install pdo_mysql
The docker-php-ext-install command is provided by the official php
image.
Build image
docker build php-with-pdo .
Test that extension was installed
docker run -it --rm my-php-image php -m | grep pdo_mysql
You should see pdo_mysql
printed out in the console.
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment