postgresqldockerdockerfileubuntu-18.04

PostgreSQL 12 installion problem with Ubuntu 18.04 docker image


I was trying to install Postgresql-12 on an Ubuntu container, but it is giving the following error.

Reading state information... E: Unable to locate package postgresql-12 E: Unable to locate package postgresql-client-12

It looks like the Ubuntu 18 container doesn't support PostgreSQL version 12. Is there any way I can install postgresl version 12 on Ubuntu 18.04 container? Any help is appreaciated. The docker file code snippet is given below.

FROM ubuntu:18.04

RUN apt-get update && apt-get install -y gnupg dirmngr

RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8

RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common postgresql-12 postgresql-client-12

Solution

  • It seems like you are using the wrong APT package repository. Replace

    RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
    

    with

    RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list
    

    and try again. precise is the codename for Ubuntu 12.04 (which has reached its end of life years ago), but your Dockerfile uses the newer Ubuntu 18.04. The codename for Ubuntu 18.04 is bionic.

    Edit: Since I'm having problems connecting to the key server given in the Dockerfile I took a look at the PostgreSQL website and aquired the key via wget as shown there. The Dockerfile does now look like this:

    FROM ubuntu:18.04
    RUN apt-get update && apt-get install -y gnupg dirmngr wget
    RUN echo "deb https://apt-archive.postgresql.org/pub/repos/apt bionic-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 && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common postgresql-12 postgresql-client-12
    

    Notable changes are the installation of wget (2nd line) and using it to get the key (4th line).