简体   繁体   English

在docker容器中安装PHP 7扩展

[英]Install PHP 7 extensions in docker container

I've created a docker container using https://hub.docker.com/_/php/ . 我使用https://hub.docker.com/_/php/创建了一个docker容器。

I need to connect from this container to another container running postgres ( https://hub.docker.com/_/postgres/ ). 我需要从这个容器连接到另一个运行postgres的容器( https://hub.docker.com/_/postgres/ )。 However, I can't seem to get the PHP 7 PDO drivers for postgres to install properly. 但是,我似乎无法正确安装postgres的PHP 7 PDO驱动程序。

Here's what my Dockerfile looks like: 这是我的Dockerfile样子:

FROM php:7.0-cli
COPY ./app /app
WORKDIR /app
RUN apt-get update && apt-get install -y \
    postgresql-client  \
    && docker-php-ext-install -j$(nproc) pgsql
CMD [ "php", "./do_stuff.php" ]

in place of pgsql I've tried pdo-pgsql , php7.0-pgsql , and tried adding a line to add the ppa:ondrej/php repo to pull from with no luck. 代替pgsql我试过pdo-pgsqlphp7.0-pgsql ,并尝试添加一行来添加ppa:ondrej/php repo来拉动没有运气。

Most of the packages fail to install (even pdo-pgsql which was suggested by docker after failing to find php7.0-pgsql ), but the odd one that does install still throws an error that the drivers aren't found when trying to create a PDO connection. 大多数软件包都无法安装(即使是在未能找到php7.0-pgsql后由php7.0-pgsql建议的pdo-pgsql ),但是安装的奇怪软件仍会抛出一个错误,即在尝试创建时找不到驱动程序PDO连接。

Is there a right way to get the PDO drivers for postgres installed in a docker container? 有没有正确的方法来获得在docker容器中安装的postgres的PDO驱动程序?

Ensure the extension is symlinked in /etc/php/7/cli/conf.d or /etc/php/7/fpm/conf.d - folders depend on your distribution. 确保扩展名在/etc/php/7/cli/conf.d或/etc/php/7/fpm/conf.d中符号链接 - 文件夹取决于您的发行版。

You can find out if the module is loaded by running 您可以通过运行来确定模块是否已加载

php -m
php7-fpm -m

if the module is missing, check /etc/php/7/modules if the .ini file is present there and symlink it, then the module should get loaded. 如果模块丢失,检查/ etc / php / 7 / modules是否存在.ini文件并对其进行符号链接,然后模块应该加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM