在php7-fpm Docker容器中安装postgre驱动程序

在php7-fpm Docker容器中安装postgre驱动程序

问题描述:

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.

我使用docker-compose命令安装了 PHP:latest code> Docker容器。 它在我的Docker中安装了 php-7.1.6-fpm code>。 当我尝试安装 php7-pgsql code>扩展时,它无法找到该包,而是找到 pdo code>和 pdo_pgsql code>包。 那不能满足我的需要。 当我在已安装的PHP容器中搜索可用的包时,我找不到 php7 code>的任何相关pgsql包,相反,我看到 php5-pgsql code>包,不会 使用php7-fpm。 p>

最后,在删除旧的目标以使用 php5-pgsql code>包之后,我安装了php-5.6-fpm容器。 但现在我又失望了,我在新安装的容器中找不到 php5-pgsql code>包。 p>

我知道我会遗漏一些重点。 Alpine Linux是否没有 php-pgsql code>扩展名。 在PHP容器中包含此扩展的可能方法有哪些。 我还在我的docker-compose.yml中包含了Nginx和Postgres。 p>

我在Docker中只有3天的理论知识和第一天的实践经验。 p>

感谢您阅读。 p> div>

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

Hope this helps ;)