skip to Main Content

I’m learning Docker so I tried to dockerize an old proyect I made a little ago, it is a Symfony 5 app, its like a shop app so it uses a mysql database.

I have the following docker compose

version: '3.7'
services:
  php:
    build: 
        context: .
        dockerfile: docker/build/php/Dockerfile
    ports: 
        - "9090:80"

  mysql:
    image: mysql:5.7
    environment: 
        - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}

Now, inside docker/build/php/Dockerfile

FROM php:7.3.3-apache

COPY . /var/www/html

When I build the image and then run docker-compose up it all seems to work fine, when I go to localhost:9090 I get an error about permissions so I run chmod -R 777 var inside the php-apache container to fix it, I refresh the page then I got An exception occurred in driver: could not find driver

Searching on google I found several solutions that says something like I need to run this command to fix it

sudo apt-get install php7.2-mysql

When I run that this happens

E: Unable to locate package php7.2-mysql

E: Couldn’t find any package by glob ‘php7.2-mysql’

E: Couldn’t find any package by regex ‘php7.2-mysql’

Or this one

apt-get install php-mysql

This throws this error

Package ‘php-mysql’ has no installation candidate

Any other command about installing something throws an error like one of the two from above, how can I fix this driver error?

There are some info about my container

root@a15f68bd3605:/# cat /etc/*-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@a15f68bd3605:/# uname -a
Linux a15f68bd3605 4.19.76-linuxkit #1 SMP Tue May 26 11:42:35 UTC 2020 x86_64 GNU/Linux

This is my .env from the symfony project

DATABASE_URL=mysql://root:@127.0.0.1:3306/popcollector?serverVersion=5.7

2

Answers


  1. in general it is a bad practice to install software inside a container afterwards. make sure to use the correct container in first place.

    you can use the webdevops container for example. To use that, simply replace the line FROM php:7.3.3-apache in your Dockerfile with FROM webdevops/php:debian-8-php7

    More info about the webdevops container on https://github.com/webdevops/Dockerfile

    Login or Signup to reply.
  2. You need to enable the pdo_mysql extension in the container.
    You can do that by adding this line to your Dockerfile:

    RUN docker-php-ext-install pdo_mysql
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search