Docker problem to connect nginx/php/mysql

I’m trying to setup a docker for some PHP projects for local environment. I have created docker-compose file:

############
## This is the LOCAL docker-compose. local is not in the file to make it default,
## easy for development.
############
version: '3.5'
services:
  nginx:
    build: ./docker/images/nginx
    image: project/nginx:latest
    ports:
      - "80:80"
    expose:
      - "80"
    volumes:
      - project_volume:/var/www/vhosts/abboom
    networks:
      project:
        aliases:
          - project.local.net
    environment:
       - VIRTUAL_HOST=project.local.net
  php:
    build: ./docker/images/php
    image: project/php:latest
    ports:
      - "7778:7778"
    expose:
      - "9000"
    volumes:
      - project_volume:/var/www/vhosts/project
    networks:
      - project
  workspace:
    build: ./docker/images/workspace
    image: project/workspace:latest
    volumes:
      - project_volume:/var/www/vhosts/project
    working_dir: /var/www/vhosts/project
    networks:
      - project
  redis_disk:
    build: ./docker/images/redis_disk
    image: project/redis:latest
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - project
  mysql:
    image: project/mysql:latest
    build: ./docker/images/mysql
    environment:
      MYSQL_ROOT_PASSWORD: secret
    volumes:
      - mysqldata:/var/lib/mysql
    networks:
      - project
    ports:
      - "33066:3306"
networks:
  project:
    name: project

volumes:
  mysqldata:
    driver: local
  redis_data:
    driver: local
  project_volume:
    driver: local
    driver_opts:
      type: nfs
      device: "$PWD/project"
      o: bind

also probably I need to share the nginx virtual host for a project (I took this virtual host config from the staging server, maybe it require some more changes?)

server {
    listen       80;
    server_name project.local.net;
    root         /var/www/vhosts/project/public;

    index index.php;

    access_log  /var/log/nginx/host.access.log  main;

    # redirect server error pages to the static page /50x.html
    #
    error_page   400 404 500 502 503 504  /500.html;
    location = /500.html {
    }

    location ~ /(assets/|content/|images/|stylesheets/|javascripts/|vendor/|fonts/|favicon.ico) {
    root          /var/www/vhosts/project/public;
    }

    location / {
            root           /var/www/vhosts/project/public;
            try_files $uri $uri/ /index.php?$args;
            fastcgi_pass   php:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;

    }
}

So the issue is that I’m getting the error Uncaught PDOException: could not find a driver in when I’m trying to access the site from a browser, but when I, for example, running migration from worksapce or php container all is working correctly.

I’m assuming that for some reason nginx container is not linked with php container and trying to find the pdo driver inside of the nginx container instead of looking it in the PHP? But it also sounds like not correct, as it starts processing php scripts and stacking only on the pdo, so it connected to the php container, so I’m not sure where to look for a problem

Previously I have made docker setup for many projects but they was written with PHP frameworks like Laravel, Symfony , but this one is a handwritten project and maybe it requires some additional changes?

Updated

Here is a php Docker file:

FROM php:7.1-fpm-alpine

LABEL maintainer="Vincent Composieux <[email protected]>"

RUN set -ex 
  && apk --no-cache add 
    postgresql-dev
RUN apk add --update 
    php7-common 
    php7-fpm 
    php7-apcu 
    php7-ctype 
    php7-curl 
    php7-dom 
    php7-gd 
    php7-iconv 
    php7-json 
    php7-intl 
    php7-mcrypt 
    php7-mbstring 
    php7-opcache 
    php7-openssl 
    php7-pdo 
    php7-pdo_sqlite 
    php7-xml 
    php7-xmlwriter 
    php7-zlib 
    php7-phar 
    php7-tokenizer 
    php7-session 
    php7-simplexml 
    php7-xdebug 
    php7-bcmath
    php7-intl 
    php-fileinfo 
    php7-redis 
    php-gd 
    make 
    curl 
    nano 
    g++ 
    icu-dev 
    libxslt 
    libxslt-dev



RUN docker-php-ext-configure pdo_mysql  && docker-php-ext-install mysqli pdo_mysql && docker-php-ext-enable pdo_mysql
RUN docker-php-ext-install bcmath
RUN docker-php-ext-configure intl  && docker-php-ext-install intl
RUN docker-php-ext-install xsl

RUN rm -rf /var/cache/apk/* && rm -rf /tmp/* && 
    curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer

ADD php.ini /etc/php7/php-fpm.d/
ADD php.ini /etc/php7/cli/conf.d/
ADD php.ini /etc/php7/cli/conf.d/
ADD xdebug.ini  /etc/php7/conf.d/

ADD www.conf /etc/php7/php-fpm.d/


RUN   sed -i "s|memory_limit = 128M|memory_limit = 512M |g" /etc/php7/php.ini
RUN   sed -i "s|upload_max_file_size = 2M|upload_max_file_size = 1024M |g" /etc/php7/php.ini
RUN   sed -i "s|post_max_size = 8M|post_max_size = 1024M |g" /etc/php7/php.ini
RUN   sed -i "s|max_execution_time = 30|max_execution_time = 600 |g" /etc/php7/php.ini

CMD ["php-fpm7", "-F"]

WORKDIR /var/www/vhosts/project
EXPOSE 9000

also php -m showing pdo_mysql in the list of enabled extensions

Source: StackOverflow