【发布时间】: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