gpt4 book ai didi

ruby-on-rails - docker postgres 图像 - 初始化失败,数据库服务不健康

转载 作者:行者123 更新时间:2023-12-02 17:32:13 25 4
gpt4 key购买 nike

我正在编写一个 Github 操作,我想在其中使用 postgres:11 图像作为服务。但每次尝试启动时,我都会收到错误 初始化失败,数据库服务不健康。

Github 操作如下所示:

name: CI

on: [push]

jobs:
unit_tests:
name: 'Run unit tests'
runs-on: ubuntu-latest
services:
db:
image: postgres:11
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 15
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x
- name: Build and run tests
if: success()
working-directory: backend/ruby
env:
DATABASE_URL: postgres://postgres:@localhost:5432/surveymaster_test
RAILS_ENV: test
run: |
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rspec ./spec

错误是:
1de39762bafa: Pull complete
e72de942a5bc: Pull complete
5ed4b3beed09: Pull complete
bc4fa92d5de6: Pull complete
881ba21508a4: Pull complete
a1f3f1480763: Pull complete
0a652322d262: Pull complete
a4c4345d4a61: Pull complete
84378331cde0: Pull complete
e4b51862ee73: Pull complete
ef2d3c443e8e: Pull complete
Digest: sha256:acac53623c6e6f748e2a8a47064432095ddf8a2d04e83b49e39f3d0b2194fad7
Status: Downloaded newer image for postgres:11
docker.io/library/postgres:11
/usr/bin/docker create --name e9bbb0d5ce654fa7b92a57d3f5109fc4_postgres11_fe5d44 --label e87b52 --network github_network_397e7f044e964fdcbe2f21b74d50f6bc --network-alias db -p 5432:5432 --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 -e GITHUB_ACTIONS=true postgres:11
5a8978184b3d44077563fa1f432270bbd51e8a89edb279e089dfc0c1593a1f2e
/usr/bin/docker start 5a8978184b3d44077563fa1f432270bbd51e8a89edb279e089dfc0c1593a1f2e
5a8978184b3d44077563fa1f432270bbd51e8a89edb279e089dfc0c1593a1f2e
/usr/bin/docker ps --all --filter id=5a8978184b3d44077563fa1f432270bbd51e8a89edb279e089dfc0c1593a1f2e --filter status=running --no-trunc --format "{{.ID}} {{.Status}}"
5a8978184b3d44077563fa1f432270bbd51e8a89edb279e089dfc0c1593a1f2e Up Less than a second (health: starting)
/usr/bin/docker port 5a8978184b3d44077563fa1f432270bbd51e8a89edb279e089dfc0c1593a1f2e
/usr/bin/docker inspect --format="{{if .Config.Healthcheck}}{{print .State.Health.Status}}{{end}}" 5a8978184b3d44077563fa1f432270bbd51e8a89edb279e089dfc0c1593a1f2e
unhealthy
##[error]Failed to initialize, db service is unhealthy.

最佳答案

由于安全原因,Postgres 容器要求 postgres 用户设置密码才能启动它。
我们可以将密码添加到 PostgreSQL,如下所示:

env:
POSTGRES_PASSWORD: postgres
现在容器将启动。我们可以在这里阅读更多相关信息 Creating PostgreSQL service containers .

关于ruby-on-rails - docker postgres 图像 - 初始化失败,数据库服务不健康,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60618118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com