简体   繁体   中英

PHP and Postgresql in Docker libpq5 dependency issue

I am trying to create a PHP, Postgresql development environment using docker by following this example: https://hk.saowen.com/a/67350ecfcbbe9dd8befa286a4257d5f91565a124ba3c7776c2b1c37f8b638df0 . However, i am running into dependency issues when docker tries to install postgresql-client-9.6 . The error that I receive is postgresql-client-9.6 : Depends: libpq5 (>= 9.6.11) but 9.6.10-0+deb9u1 is to be installed

The tutorial tries using php:7.0-apache and postgres:9.6 . I have tried changing versions of both PHP and postgresql, but I am getting the same type of error with different dependcy numbers. It appears that libpq5 is out of date, and I don't know how to get a more recent version.

The Dockerfile that I am using is

FROM php:7.0-apache
RUN apt-get update && \
    apt-get install -y libpq-dev gnupg && docker-php-ext-install pdo pdo_pgsql
RUN apt-get install -y wget
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main 9.6" > /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
   apt-key add -
RUN apt-get update
RUN apt-get install -y postgresql-client-9.6
COPY ./wait-for-postgres.sh wait-for-postgres.sh
RUN chmod +x wait-for-postgres.sh
COPY src/ /var/www/html

and the docker-compose.yml file is

version: '3'
volumes:
  psql-data:

services:
  php-app:
    build: ./app
    image: myapp
    container_name: php-app
    env_file:
      - ./env
    depends_on:
      - postgres
    command: ["./wait-for-postgres.sh", "apache2-foreground"]
    ports:
      - 80:80
    networks:
      app-env:

  postgres:
    image: postgres:9.6
    container_name: postgres
    env_file:
      - ./env
    volumes:
      - ./postgres/script/:/docker-entrypoint-initdb.d
      - psql-data:/var/lib/posgresql/data
    networks:
      app-env:

networks:
  app-env:

This blog post describes the problem exactly, however the solution has not worked for me: https://support.circleci.com/hc/en-us/articles/360003953613-Error-Installing-postgresql-client-9-6-on-Docker . Thanks in advance for any advice offered.

I have similar situation where I needed to install postgresql-client-10 on my existing docker image. Instead I build required image on top of postgres:10 image. Hope this helps you as well.

Had the same problem myself. It turned out I was adding the wrong distro's repository to apt. My image was based on Debian 9 (codename stretch), but I was adding the repo or Debian 8 (codename jessie):

I had this (wrong version for me):

FROM ruby:2.5.0
RUN wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add - && \
      echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" >> /etc/apt/sources.list.d/pgdg.list

Should have been this (s/jessie/stretch/):

FROM ruby:2.5.0
RUN wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | apt-key add - && \
      echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" >> /etc/apt/sources.list.d/pgdg.list

I'm guessing your problem is that the php:7.0-apache image is not based on Ubuntu 14.04 (codename Trusty Tahr), but that's what you're repo is for.

You can check what version you have by running this:

docker run php:7.0-apache cat /etc/issue

I just did that, and it looks like that image is based on Debian Stretch as well. So in your case, just change your Dockerfile to this:

FROM php:7.0-apache
RUN apt-get update && \
    apt-get install -y libpq-dev gnupg && docker-php-ext-install pdo pdo_pgsql
RUN apt-get install -y wget
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
   apt-key add -
RUN apt-get update
RUN apt-get install -y postgresql-client-9.6
COPY ./wait-for-postgres.sh wait-for-postgres.sh
RUN chmod +x wait-for-postgres.sh
COPY src/ /var/www/html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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