Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stargatesg1's avatar

Laravel and Docker

I am trying to get mySQL working in Laravel using Docker. The website comes up but anything to do with database connection doesn't. I have installed mySQLi so I am not sure. Here is my Docker configuration

version: '3.1'
services:
  dockertemplate:
    image: nginx:latest
    ports:
      - "8080:80"
    volumes:
      - ./../public:/public
      - ./default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
    links:
      - php
  php:
    #image: php:7.2-fpm
    build: ../
    ports:
        - 9000
    volumes:
      - ./../public:/public
  mariadb:
    image: mariadb:10.4
    restart: always
    environment:
      MYSQL_DATABASE: 'mydb'
      MYSQL_ROOT_PASSWORD: '123'
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
    ports:
      - "3306:3306"
    volumes:
      - ./db/:/var/lib/mysql
  # Run adminer if we want to see db
  # Connection server is "mariadb"
  adminer:
    image: adminer
    restart: always
    ports:
      - 8081:8080

Here is my Dockerfile configuration

FROM php:7.2-fpm 
RUN docker-php-ext-install mysqli
WORKDIR /public
COPY public/* /public/
EXPOSE 9000

I am not sure what I am missing.

I am getting the following error

"could not find driver (SQL: select * from users)"

0 likes
2 replies
stargatesg1's avatar

My configuration is very similar I also made some changes to the Dockerfile and still same issue

Here is the new DockerFile

FROM php:7.2-fpm

# Install extensions
RUN docker-php-ext-install pdo_mysql 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
1 like

Please or to participate in this conversation.