Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable pdo_mysql in the php docker image [duplicate]

Tags:

php

docker

mysql

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.

enter image description here

Are there any steps I am missing?

like image 352
Tom Avatar asked Jun 17 '17 11:06

Tom


3 Answers

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.

like image 56
Nigel Ren Avatar answered Oct 18 '22 23:10

Nigel Ren


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

like image 43
Ahmad Al ALloush Avatar answered Oct 18 '22 23:10

Ahmad Al ALloush


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 \
    ...
like image 6
VonC Avatar answered Oct 18 '22 21:10

VonC