Sorry if this is obvious, I am quite new to docker…
I just want to connect a container with a laravel application to a postgres container
The Dockerfile
of my laravel application is :
FROM php:7.4-fpm
RUN apt-get update && apt-get install -y libpq-dev
RUN docker-php-ext-install pdo pdo_pgsql pgsql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /app
COPY . /app
RUN composer install
CMD php artisan serve --host=0.0.0.0 --port=8181
EXPOSE 8181
No issues with this container that runs well
My docker-compose.yml
goes like this :
version: '3'
services:
laravel:
container_name: app
build:
context: .
dockerfile: Dockerfile
environment:
- DB_CONNECTION=pgsql
- DB_HOST=localhost
- DB_PORT=5432
- DB_DATABASE=postgres
- DB_USERNAME=postgres
- DB_PASSWORD=postgres
volumes:
- .:/var/www/app
- ./vendor:/var/www/app/vendor
ports:
- '8181:8181'
command: bash -c "php artisan migrate"
depends_on:
- db
links:
- db
db:
image: postgres
container_name: postgres_database
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
ports:
- '5432:5432'
volumes:
- db:/var/lib/postgresql/data
volumes:
db:
driver: local
When I run docker-compose up
I have an issue when running the migration command : I get a QueryException: could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')
If I remove the command: bash -c "php artisan migrate"
line in the docker-compose file, everything works fine and I can connect to my database using a database client
Does somebody know what is happening ?
Thanks a lot !!!