【问题标题】:Install/upgrade postgresql-client to version 12 in dockerized Ruby On Rails Application在 dockerized Ruby On Rails 应用程序中安装/升级 postgresql-client 到版本 12
【发布时间】:2020-12-18 17:51:11
【问题描述】:

我已经开始开发由 APP、API 和 DB docker 容器组成的 Ruby On Rails 应用程序。

数据库基于postgres:12 图像。

API 泊坞窗文件:

FROM ruby:2.3.3

RUN apt-get update -qq && apt-get install -y \
  postgresql-client imagemagick ghostscript nodejs

WORKDIR /app

COPY docker-entrypoint-api.sh /usr/bin/
RUN chmod +x /usr/bin/docker-entrypoint-api.sh
ENTRYPOINT ["docker-entrypoint-api.sh"]

对于数据库架构,我使用的是structure.sql,迁移数据库的命令是:

docker-compose run --rm api rails db:migrate

但它会导致错误:

pg_dump: server version: 12.3 (Debian 12.3-1.pgdg100+1); pg_dump version: 9.4.26
pg_dump: aborting because of server version mismatch
rails aborted!
failed to execute:
pg_dump -s -x -O -f /app/db/structure.sql my_app_development

我尝试将 postgresql-client 升级到版本 12,现在以下 API dockerfile 是:

FROM ruby:2.3.3

RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee  /etc/apt/sources.list.d/pgdg.list

RUN apt-get update -qq && apt-get install -y \
  postgresql-12 postgresql-client-12 imagemagick ghostscript nodejs

WORKDIR /app

COPY docker-entrypoint-api.sh /usr/bin/
RUN chmod +x /usr/bin/docker-entrypoint-api.sh
ENTRYPOINT ["docker-entrypoint-api.sh"]

重建我所有的 docker 镜像会导致:

db uses an image, skipping
redis uses an image, skipping
Building api
Step 1/8 : FROM ruby:2.3.3
 ---> 0e1db669d557
Step 2/8 : RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
 ---> Using cache
 ---> c9541dccb7f1
Step 3/8 : RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee  /etc/apt/sources.list.d/pgdg.list
 ---> Running in 152c2b71a16f
/bin/sh: 1: lsb_release: not found
deb http://apt.postgresql.org/pub/repos/apt/ -pgdg main
Removing intermediate container 152c2b71a16f
 ---> 01ec3f989c11
Step 4/8 : RUN apt-get update -qq && apt-get install -y   postgresql-12 postgresql-client-12 imagemagick ghostscript nodejs
 ---> Running in f2a918ff27e2
W: There is no public key available for the following key IDs:
AA8E81B4331F7F50
W: Failed to fetch http://apt.postgresql.org/pub/repos/apt/dists/-pgdg/main/binary-amd64/Packages  404  Not Found [IP: 87.238.57.227 80]

E: Some index files failed to download. They have been ignored, or old ones used instead.
ERROR: Service 'api' failed to build: The command '/bin/sh -c apt-get update -qq && apt-get install -y   postgresql-12 postgresql-client-12 imagemagick ghostscript nodejs' returned a non-zero code: 100

关于如何解决这个问题有什么建议吗?

【问题讨论】:

    标签: ruby-on-rails postgresql docker


    【解决方案1】:

    docker 构建日志中的第一个错误通常是根本原因:/bin/sh: 1: lsb_release: not found

    你有两个选择。

    选项 1. 硬编码发布代码名称

    优点:Docker 构建速度更快、映像更小、攻击面更小。
    缺点:如果/当您升级到较新的基础映像时,可能需要手动更新字符串。

    FROM ruby:2.3.3
    
    RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
    RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ jessie-pgdg main" | tee  /etc/apt/sources.list.d/pgdg.list
    
    RUN apt-get update -qq && apt-get install -y \
      postgresql-client-12 imagemagick ghostscript nodejs
    
    WORKDIR /app
    
    COPY docker-entrypoint-api.sh /usr/bin/
    RUN chmod +x /usr/bin/docker-entrypoint-api.sh
    ENTRYPOINT ["docker-entrypoint-api.sh"]
    

    我为什么选择jessie

    docker run ruby:2.3.3 cat /etc/os-release 显示有关映像操作系统的信息。

    选项 2. 安装缺少的命令

    优点:如果您升级基本映像,则不太可能中断。
    缺点:Docker 构建速度较慢、映像更大、攻击面增加。

    FROM ruby:2.3.3
    
    RUN apt-get update -qq && apt-get install lsb-core
    RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
    RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee  /etc/apt/sources.list.d/pgdg.list
    
    RUN apt-get update -qq && apt-get install -y \
      postgresql-client-12 imagemagick ghostscript nodejs
    
    WORKDIR /app
    
    COPY docker-entrypoint-api.sh /usr/bin/
    RUN chmod +x /usr/bin/docker-entrypoint-api.sh
    ENTRYPOINT ["docker-entrypoint-api.sh"]
    

    【讨论】:

    • 比你,第一种就好了
    猜你喜欢
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    • 2012-06-21
    • 2014-07-13
    相关资源
    最近更新 更多