Unable to locate package in docker image

Viewed 2413

I am trying to setup a docker image for an app using laravel and postgres but I'm running into difficulties trying to install the php driver for postgres.

My Dockerfile:

FROM php:7.4-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip \
    postgresql-client \
    libpq-dev \
    php7.4-pgsql

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd 

# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

# Set working directory
WORKDIR /var/www

USER $user

The error I am receiving:

E: Unable to locate package php7.4-pgsql
E: Couldn't find any package by glob 'php7.4-pgsql'
E: Couldn't find any package by regex 'php7.4-pgsql'
ERROR: Service 'app' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y php7.4-pgsql' returned a non-zero code: 100
1 Answers

It looks like pgsql is not included in the PHP Docker image.

I used docker-php-extension-installer to add the extensions I need to my Docker image.

I added the following two lines into my dockerfile and everything is working as expected now

ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/

RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
    install-php-extensions pdo_pgsql
Related