0

Im trying to run a laravel application in a container and I get driver could not be found on migrate. Laravel 8, mysql 8, php 8

docker compose

version: "3.9"
services:
  #PHP Service
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: app
    restart: unless-stopped
    tty: true
    environment:
      SERVICE_NAME: app
      SERVICE_TAGS: dev
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - app-network

  #Nginx Service
  webserver:
    image: nginx:latest
    container_name: webserver
    restart: unless-stopped
    tty: true
    ports:
      - "8005:80"
      - "8006:443"
    volumes:
      - ./:/var/www
      - ./docker/nginx/conf.d/:/etc/nginx/conf.d/
    networks:
      - app-network

  #Mariadb Service
  db:
    image: mysql
    container_name: db
    restart: unless-stopped
    tty: true
    environment:
      MYSQL_DATABASE: test
      MYSQL_ROOT_PASSWORD: test
      SERVICE_TAGS: dev
      SERVICE_NAME: db
    volumes:
      - dbdata:/var/lib/mysql1
      - ./docker/sqldb/db.cnf:/etc/sqldb/db.cnf
    networks:
      - app-network

#Docker Networks
networks:
  app-network:
    driver: bridge

#Volumes
volumes:
  dbdata:
    driver: local

Dockerfile

FROM php:fpm

# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/

# Copy existing application directory contents
COPY . /var/www

# Set working directory
WORKDIR /var/www

# Give permissions
RUN chown -R www-data:www-data .
RUN find . -type f -exec chmod 664 {} \;
RUN find . -type d -exec chmod 775 {} \;
RUN chgrp -R www-data storage bootstrap/cache
RUN chmod -R ug+rwx storage bootstrap/cache

RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-install mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd


# Expose port 9000 and start php-fpm server
EXPOSE 9000

.env

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=test

# I have also tried creating another user and granting all privileges to it, same thing

Its some missing extension I cant figure what is it, maybe im installing pdo incompatible with php 8? The user and database are correctly created.

error

Illuminate\Database\QueryException 

  could not find driver (SQL: select * from information_schema.tables where table_schema = test and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
    674▕         // If an exception occurs when attempting to run a query, we'll format the error
    675▕         // message to include the bindings with SQL, which will make this exception a
    676▕         // lot more helpful to the developer instead of just the database's errors.
    677▕         catch (Exception $e) {
  ➜ 678▕             throw new QueryException(
    679▕                 $query, $this->prepareBindings($bindings), $e
    680▕             );
    681▕         }
    682▕ 

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

note: I have tried many solutions on many different answers here on stackoverflow

Thank you!

Edit:: phpinfo() has PDO (sqlite enabled), and pdo_sqlite (3.27.2) and mysqlnd 8.0.6 Thats the only db drivers i can see, maybe its something to do with local.ini I add using docker-compose

here's local.ini

upload_max_filesize=40M
post_max_size=40M

# tried adding extension=php_pdo_mysql.so, no luck
  • Can you help us out by confirming if the driver is actually installed by following one of these examples? https://stackoverflow.com/a/3131609/296555 – waterloomatt May 28 '21 at 14:24
  • As pointed in that referenced comment, here's the result: an error is thrown on var_dump(defined(PDO::MYSQL_ATTR_LOCAL_INFILE)); // mysql, undefined constant, extension loaded PDO, true, pdo_mysql (FALSE!), loaded extensions: Core ctype curl date dom fileinfo filter ftp hash iconv json libxml mbstring mysqlnd openssl pcre PDO pdo_sqlite Phar posix readline Reflection session SimpleXML sodium SPL sqlite3 standard tokenizer xml xmlreader xmlwriter zlib --- I have something that you might find interesting, but perhaps its something to do with local.ini of php. not sure –  May 28 '21 at 18:17
  • Try removing the line from docker-compose.yml that creates a volume mount to your .ini file. Make sure to rebuild your image to ensure that the file isn't read by the container. I don't see anything obviously wrong with your setup and suspect you're right in that something is overwriting the initial config. You may have to `rm` that volume in order to completely separate it from the container. – waterloomatt May 28 '21 at 19:05
  • Try running `php artisan migrate` inside the container. – Jan Madeyski May 18 '22 at 23:01

0 Answers0