I have a basic Dockerfile
with the following in:
FROM php:7.1-apache
RUN apt-get update && docker-php-ext-install pdo_mysql
COPY . /var/www
EXPOSE 80
I have a docker-compose.yml file
version: "3"
services:
app:
build: .
ports:
- "80:80"
volumes:
- .:/var/www
depends_on:
- mysql
mysql:
image: mysql:8
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: "app"
MYSQL_USER: "app"
MYSQL_PASSWORD: "app"
MYSQL_ROOT_PASSWORD: "test"
I then ran docker build -t app . && docker-compose up
at the root of the project. Everything seems to build correctly, but when outputting phpinfo
I don't see the mysql_pdo extension.
Are there any steps I am missing?
The docker file I use is...
FROM php:7.1-apache
COPY apache2.conf /etc/apache2
RUN docker-php-ext-install mysqli pdo pdo_mysql
Note the mysqli and pdo in there as well to allow the PDO/mysql bit.
to enabled PHP PDO and mysqli extensions to connect with MySQL add in Dockerfile :
RUN docker-php-ext-install pdo pdo_mysql
# for mysqli if you want
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
More Information to how to create that visit this Page
There was a similar error in docker php issue 62:
As it turn out that I need to remove the old images and rebuild them again.
Cause I downloaded the image, then edit it. So I need to remove the old image and rebuild it in order to apply the change.
docker rm only removes containers. Make sure you remove your image as well before.
Also check if a Dockerfile like this one might be more robust/complete:
# PHP extensions
RUN \
docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-configure mysqli --with-mysqli=mysqlnd \
&& docker-php-ext-install pdo_mysql \
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With