我已经开始开发Rails应用程序,它由应用程序、API和DB停靠容器组成。
DB基于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升级到版本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"]重建我所有的码头映像会导致:
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对于如何解决这个问题,有什么建议吗?
发布于 2020-12-18 19:29:06
停靠程序构建日志中的第一个错误通常是根本原因:/bin/sh: 1: lsb_release: not found
你有两个选择。
选项1.硬编码发布代码名
优点:更快的码头建设,更小的形象,更小的攻击表面。
缺点:升级到更新的基本映像时,可能需要手动更新字符串。
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.安装缺失的命令
优点:如果你升级基本形象,不太可能破坏。
缺点:较慢的码头建造,较大的图像,增加攻击表面。
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"]https://stackoverflow.com/questions/65361694
复制相似问题