Aug 23, 2023
0
Level 1
Laravel, docker and postgresql
Dockerfile:
FROM php:8.1-fpm
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
zip \
unzip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install pdo_pgsql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/html
COPY composer.json composer.lock /var/www/html/
RUN composer install --no-scripts
COPY . /var/www/html
RUN chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
CMD ["php-fpm"]
docker-compose.yml
version: '3.7'
services:
php:
image: php:8.1-fpm
container_name: my-laravel-app-php
volumes:
- ./application:/var/www/html
working_dir: /var/www/html
networks:
- laravel-net
nginx:
image: nginx:latest
container_name: my-laravel-app-nginx
ports:
- "80:80"
volumes:
- ./application:/var/www/html
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
networks:
- laravel-net
postgres:
image: postgres:latest
container_name: my-laravel-app-postgres
environment:
POSTGRES_DB: laravel_db
POSTGRES_USER: laravel_user
POSTGRES_PASSWORD: secret_password
volumes:
- pg-data:/var/lib/postgresql/data
networks:
- laravel-net
networks:
laravel-net:
volumes:
pg-data:
In the .env file, I use the data specified in the environment in postgres to connect to the database, but the connection is still missing, what should I do?
when executing DB::connection()->getPdo(); i get a PDOException could not find driver. how is this possible if the installation is in the Dockerfile?
Please or to participate in this conversation.