-1

i am runing this docker composer files with this enviroment:

version: "3.1"
services:
  mysql:
    container_name: mysql
    image: 'mysql:8.0'
    working_dir: /application
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
      - '.:/application'
    environment:
      - MYSQL_ROOT_PASSWORD=1qazxsw22
      - MYSQL_DATABASE=minos
      - MYSQL_PASSWORD=1qazxsw22
    ports:
      - "3308:3306"
  webserver:
    container_name: webserver
    image: 'nginx:alpine'
    working_dir: /application
    volumes:
      - '.:/application'
      - './conf-example/nginx/nginx.conf:/etc/nginx/conf.d/default.conf'
    ports:
      - '8008:80'
    depends_on:
      - mysql
    links:
      - mysql:minos
  php-fpm:
    build: conf-example/php-fpm
    working_dir: /application
    volumes:
      - '.:/application'
      - './conf-example/php-fpm/php-ini-overrides.ini:/etc/php/8.1/fpm/conf.d/99-overrides.ini'

and Dockerfile instalation look like this:

FROM phpdockerio/php:8.1-fpm
LABEL maintainer="ChaosEmperorDragonEnvoyoftheEnd"
LABEL version="1.0.0"

WORKDIR "/application"

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV DATE_TIMEZONE UTC
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update; \
    apt-get -y --no-install-recommends install \
        build-essential \
        curl \
        git \
        mysql-client \
        nano \
        unzip \
        wget \
        zip \
        apache2 \
        libapache2-mod-php \
        libmcrypt-dev \
        cron \
        locales \
        php8.1 \
        php8.1-fpm \
        php8.1-cli \
        php8.1-gd \
        php8.1-common \
        php8.1-curl \
        php8.1-imap \
        php8.1-intl \
        php8.1-json \
        php8.1-mailparse \
        php8.1-mbstring \
        php8.1-mysql \
        php8.1-pear \
        php8.1-readline \
        php8.1-soap \
        php8.1-xml \
        php8.1-xmlrpc \
        php8.1-zip \
        php8.1-bz2 \
        php8.1-dba \
        php8.1-ldap \
        php8.1-dev \
        php8.1-xdebug \
    apt-get clean; \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

to implement a webserver lamp stack but when i try to run index.php to connect from php to mysql like this:

<?php

try {
    $dbh = new PDO(
        'mysql:mysql:3308;dbname=minos',
        'minos',
        '1qazxsw22',
        array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
    );
} catch (PDOException $e) {
    echo $e->getMessage();
}

i get this error:

could not find driver

What do I need to change in my code or installation to remove this error of conecctivity?

  • Reviewing this URL may help you resolve your connecting issue. https://www.php.net/manual/en/pdo.connections.php Good Luck. – Wilson Hauck Oct 14 '22 at 13:05

1 Answers1

0

Try running like this:

RUN apt update \
    && apt -y --no-install-recommends install php-mysql php-curl php-intl php-gd php-common php-redis php-sodium git \
    && apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

Change form php8.1-lib to php-lib