Home >Database >Mysql Tutorial >How to Install the PDO MySQL Driver in Your PHP Docker Image?

How to Install the PDO MySQL Driver in Your PHP Docker Image?

Susan Sarandon
Susan SarandonOriginal
2024-11-08 20:05:01867browse

How to Install the PDO MySQL Driver in Your PHP Docker Image?

Install PDO Driver in PHP Docker Image

Background:

You're encountering an error while trying to access a database in your PHP application within a Docker container. The error indicates that the PDO MySQL driver is missing.

Solution:

The official PHP repository provides a script for installing PHP extensions in Docker containers: docker-php-ext-install. To resolve this issue:

  1. Create a Custom Docker Image:
FROM php:5.6-apache

# Install PDO extension
RUN docker-php-ext-install pdo pdo_mysql
  1. Rebuild and Install Custom Image:

Build and install the customized Docker image with the PDO extension:

docker build -t custom-php-image .
docker run -it --rm --name my-app custom-php-image

Now, your Docker container will have the PDO MySQL driver installed and you should be able to access your database without encountering the PDO driver missing error.

The above is the detailed content of How to Install the PDO MySQL Driver in Your PHP Docker Image?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn