Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing Postgres driver in php7-fpm Docker container

I've installed PHP:latest Docker container using the docker-compose command. It installed php-7.1.6-fpm in my Docker. When I tried to install php7-pgsql extension it failed to find that package, instead found pdo and pdo_pgsql packages. That will not satisfy my need. When I search for the available packages in the installed PHP container, I could not find any related pgsql packages for php7, instead, I saw php5-pgsql package, that will not work with php7-fpm.

Finally, I installed php-5.6-fpm container after removing the old one targeting to use php5-pgsql package. But now I disappointed again that I could not find php5-pgsql package in the newly installed container.

I know I'll be missing some important points. Whether Alpine Linux does not have php-pgsql extension. What are the possible ways to include this extension in my PHP container. I've also included Nginx and Postgres in my docker-compose.yml

I've only 3-day theory knowledge in Docker and first-day practical experience.

Thanks for reading.

like image 730
Sony George Avatar asked Jul 08 '17 08:07

Sony George


People also ask

How to install PostgreSQL in Docker?

Install the PostgreSQL client package on the localhost. Access the PostgreSQL service running on the Docker container. Here is the command output: Congratulations! Your PostgreSQL Docker installation was tested successfully.

How do I set up the PHP FPM Docker container?

In short, in order to set up the PHP FPM docker container, we need to build an ubuntu 14 image. In this article, we saw how our Support Techs perform the same for our customers. PREVENT YOUR SERVER FROM CRASHING! Never again lose customers to poor server speed!

What is docker compose configuration for PHP?

This Docker Compose configuration lets you run easily PHP 7.1 with Nginx, PHP-FPM, PostgreSQL 10.1 and Composer. It exposes 4 services: db (PostgreSQL 10.1)

How do I connect to PostgreSQL server?

There are two ways to connect to the PostgreSQL server. We can use Link Containers , or we can access it from our host (or the network). Note: The --rm removes the container and its image when the container exits successfully.


2 Answers

I ran into the same issue when I was settings up a new project to use pgsql.

I am using php7, so you should be able to use it as well. On your Dockerfile ensure you're covering the following steps.

Ensure you have the dependencies installed:

RUN apt-get update && apt-get install -y libpq-dev

Configure the extension:

RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql

Install the extension:

RUN docker-php-ext-install pdo pdo_pgsql
like image 167
Bernardo Silva Avatar answered Nov 14 '22 22:11

Bernardo Silva


This is an old question i know, but i ran into this today and believe the above solution has changed with php:7.4-fpm-alpine

So where it used to be:

RUN apt-get update && apt-get install -y libpq-dev

Should now be:

RUN apt-get update && apt-get install -y postgresql-dev

Hopefully this helps anyone that runs into the same issue.

like image 30
Devon Ray Avatar answered Nov 14 '22 22:11

Devon Ray