我尝试在 Ubuntu 容器上安装 Postgresql-12,但出现以下错误。
正在读取状态信息... E: 无法找到包 postgresql-12 E: 无法找到包 postgresql-client-12
Ubuntu 18 容器似乎不支持 PostgreSQL 版本 12。 有什么方法可以在 Ubuntu 18.04 容器上安装 postgresl 版本 12 吗? 任何帮助表示赞赏。下面给出了 docker 文件代码片段。
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
您似乎使用了错误的 APT 软件包存储库。更换
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" > /etc/apt/sources.list.d/pgdg.list
与
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main" > /etc/apt/sources.list.d/pgdg.list
然后再试一次。
precise
是 Ubuntu 12.04 的代号(几年前就已结束生命),但您的 Dockerfile 使用较新的 Ubuntu 18.04。 Ubuntu 18.04 的代号是 bionic
。
编辑: 由于我在连接到 Dockerfile 中给出的密钥服务器时遇到问题,我查看了 PostgreSQL 网站 并通过
wget
获取了密钥,如图所示。 Dockerfile 现在看起来像这样:
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
显着的变化是安装
wget
(第2行)并使用它来获取密钥(第4行)。