The pdo_mysql extension is not detected on WordPress Docker container

Solution:1

Your wordpress image used in this stack is default image of Docker Hub and they have very detail documentation of how to install new PHP extension.

First we have to edit some changes on your docker-compose.yml file to make new wordpress custom build:

wordpress:
     depends_on:
       - db
     container_name: ${CONTAINER_WP_NAME}
     # image: wordpress:latest
     build: ./wordpress

Second, create a new file called Dockerfile and docker-entrypoint.sh of WordPress default image here, place it inside wordpress directory. Amend some magic code to wordpress/Dockerfile file:

RUN docker-php-ext-install pdo pdo_mysql

Now you have your custom Docker stack with PDO_MYSQL extension and able to run your backup process.

Your stack’s config after edit: https://github.com/tdtgit/stackoverflow57447284

Feel free to comment if you need help.

Solution:2

If you see errors related to ‘PDO_MySQL’ you may be missing the Docker extension.
You can find more about extensions here: PHP: Membership – Manual
Here is the page for PDO_MySQL: PHP: MySQL (PDO) – Manual

The PHP page on Dockerhub has examples of installing these extensions
https://hub.docker.com/_/php/
If you scroll way down to PHP Core Extensions You can see an example of installing an extension.

RUN docker-php-ext-install -j$(nproc) iconv mcrypt

You will also need to enable it via docker-php-ext-enable pdo_mysql

Example:
steps:
- run:
name: Install PHP extensions
command: |
sudo docker-php-ext-install pdo_mysql
sudo docker-php-ext-enable pdo_mysql