1

我有一个带有 postgresql 数据库的 API 平台项目,但我找不到如何使用 docker 启用 pdo pgsql 驱动程序。

这是我的码头文件:

FROM php:7.1-apache

# PHP extensions
ENV APCU_VERSION 5.1.7
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
    libicu-dev \
    zlib1g-dev \
    libpq-dev \
    libzip-dev \
    libpcre3-dev \
    ssmtp vim git cron zip \
    && docker-php-ext-install \
    pdo \
    pdo_pgsql \
    zip

# Apache config
RUN a2enmod rewrite
ADD docker/apache/vhost.conf /etc/apache2/sites-available/000-default.conf

# Add the application
ADD . /app
WORKDIR /app

# Install composer
RUN ./docker/composer.sh \
    && mv composer.phar /usr/bin/composer \
    && composer global require "hirak/prestissimo:^0.3"

RUN usermod -u 1000 www-data
#RUN chown -R www-data:www-data /app/var/cache /app/var/logs /app/var/sessions

CMD ["/app/docker/start.sh"]

这里是我的 docker-composer.yml 文件

web:
    container_name: web-api-front
    build: .
    environment:
        SYMFONY_ENV: dev
    volumes:
        - .:/app
    ports:
        - 8084:80

psql:
    container_name: psql-api-front
    image: postgres
    environment:
        POSTGRES_PASSWORD: ''
        POSTGRES_USER: dbuser
        POSTGRES_DB: dbname
    ports:
        - "5433:5432"
    volumes:
        - ./docker/sql:/var/sql

我尝试了很多网站,但我仍然找不到启用 pgsql 的方法..

当我做

var_dump(PDO::getAvailableDrivers());

我只有

array(2) { [0]=> string(6) "sqlite" [1]=> string(5) "mysql" }

另外,当我跑步时

docker-compose up

我的日志中有这个,我不确定这是什么意思

psql-api-front | LOG:  database system was shut down at 2017-08-01 08:18:57 UTC
psql-api-front | LOG:  MultiXact member wraparound protections are now enabled
psql-api-front | LOG:  database system is ready to accept connections
psql-api-front | LOG:  autovacuum launcher started

我究竟做错了什么 ?

4

1 回答 1

3

这意味着 PSQL 工作正常,但为了让 apache 正常工作,您需要添加 psql 库和驱动程序:

FROM php:7.1-apache

# PHP extensions
ENV APCU_VERSION 5.1.7
RUN buildDeps=" \
        libicu-dev \
        zlib1g-dev \
        libsqlite3-dev \
        libpq-dev \
    " \
    && apt-get update \
    && apt-get install -y --no-install-recommends \
        $buildDeps \
        libicu52 \
        zlib1g \
        sqlite3 \
        git \
        php5-pgsql \
    && rm -rf /var/lib/apt/lists/* \
    && docker-php-ext-install \
        intl \
        mbstring \
        pdo_mysql \
        pdo_pgsql \
        pdo \
        pgsql \
        zip \
        pdo_sqlite \
    && apt-get purge -y --auto-remove $buildDeps
RUN pecl install \
        apcu-$APCU_VERSION \
        xdebug \
    && docker-php-ext-enable xdebug \
    && docker-php-ext-enable --ini-name 05-opcache.ini \
        opcache \
    && docker-php-ext-enable --ini-name 20-apcu.ini \
        apcu

ARG SYMFONY_ENV=dev
ENV SYMFONY_ENV=dev
RUN if [ "$SYMFONY_ENV" -ne "dev" ]; then \
        sed -i '1 a xdebug.remote_enable=1' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_handler=dbgp' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_autostart=0' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_connect_back=1 ' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_port=9001' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini && \
        sed -i '1 a xdebug.remote_log=/var/log/xdebug_remote.log' /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; \
    fi;

# Apache config
RUN a2enmod rewrite
ADD docker/apache/vhost.conf /etc/apache2/sites-available/000-default.conf

# PHP config
ADD docker/php/php.ini /usr/local/etc/php/php.ini

# Add the application
ADD . /app
WORKDIR /app
RUN chmod +x /app/docker/composer.sh
# Install composer
RUN /app/docker/composer.sh \
    && mv composer.phar /usr/bin/composer \
    && composer global require "hirak/prestissimo:^0.3"
ENV PATH="$PATH:$HOME/.composer/vendor/bin"

# to define
ARG INSTALL_DEP=true

RUN if [ -n "$INSTALL_DEP" ]; then \
    if [ "$SYMFONY_ENV" -ne "prod" ]; then \
        composer install --prefer-dist --no-scripts --no-dev --no-progress --no-suggest --optimize-autoloader --classmap-authoritative && composer run-script continuous-pipe; \
    else \
    composer install -o --no-interaction --prefer-dist --no-scripts && composer run-script continuous-pipe; \
    fi; \
    fi;

# Remove cache and logs if some and fixes permissions
RUN rm -rf var/cache/* && rm -rf var/logs/* && rm -rf var/sessions/* && chmod a+r var/ -R

# Apache gets grumpy about PID files pre-existing
RUN rm -f /var/run/apache2/apache2.pid

RUN a2enmod ssl

EXPOSE 443

CMD ["/app/docker/apache/run.sh"]

这应该可以正常工作,您可以与您现有的配置进行比较。

于 2017-08-01T08:35:29.740 回答