简体   繁体   English

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

[英]docker postgres image - Failed to initialize, db service is unhealthy

I am writing a Github action where I want to use postgres:11 image as a service.我正在编写一个 Github 操作,我想在其中使用 postgres:11 图像作为服务。 But everytime, it tries to start I get error Failed to initialize, db service is unhealthy.但每次尝试启动时,我都会收到错误无法初始化,数据库服务不健康。

Github action looks like: 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

The error is:错误是:

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 container requires that postgres user be setup with password in order to start it due to security reasons.由于安全原因,Postgres 容器要求 postgres 用户设置密码才能启动它。 we can add the password to the PostgreSQL like following:我们可以将密码添加到 PostgreSQL,如下所示:

env:
  POSTGRES_PASSWORD: postgres

Now the container will be up.现在容器将启动。 We can read more about it here Creating PostgreSQL service containers .我们可以在这里阅读更多关于它的信息创建 PostgreSQL 服务容器

changing the docker version to:将 docker 版本更改为:

postgres:11@sha256:85d79cba2d4942dad7c99f84ec389a5b9cc84fb07a3dcd3aff0fb06948cdc03b

solved it for me apparently with latest 11 version due to some security related changes we get this issue.由于一些与安全相关的更改,我们遇到了这个问题,显然使用最新的 11 版本为我解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Docker、Rails、Postgres - 找不到数据库服务错误 - Docker, Rails, Postgres - db service not found error 如何在Postgres DB上使find_or_initialize区分大小写? - How to make find_or_initialize case insensitive on a Postgres DB? `初始化':postgres 方案不接受注册表部分:postgres:@(或错误的主机名?)(URI::InvalidURIError)与 Docker - `initialize': the scheme postgres does not accept registry part: postgres:@ (or bad hostname?) (URI::InvalidURIError) with Docker 无法启动服务 postgres:驱动程序在端点上编程外部连接失败 - Cannot start service postgres: driver failed programming external connectivity on endpoint 构建包含 Postgres 数据的 Docker 映像并用于 Kubernets - Build Docker image with Postgres data included and use for Kubernets 错误:对于 xxx_postgres_1 无法启动服务 postgres:b'driver 在端点 dataimobi-engine_postgres_ 上编程外部连接失败 - ERROR: for xxx_postgres_1 Cannot start service postgres: b'driver failed programming external connectivity on endpoint dataimobi-engine_postgres_ 连接到db,但rspec在`initialize'中说:FATAL:用户“sample_app”的密码验证失败(PG ::错误) - connected to db, but rspec says in `initialize': FATAL: password authentication failed for user “sample_app” (PG::Error) 使用 docker 构建 rails 应用程序时如何修复“未实现功能 - 无法初始化 inotify (Errno::ENOSYS)” - How to fix `Function not implemented - Failed to initialize inotify (Errno::ENOSYS)` when using docker to build rails app 产品中的Rails 5:PG :: ConnectionBad:严重:使用Docker的用户“ postgres”的密码身份验证失败 - Rails 5 in prod: PG::ConnectionBad: FATAL: password authentication failed for user “postgres” with Docker “错误:无法构建 gem 原生扩展”构建 Docker 图像 - "ERROR: Failed to build gem native extension" building Docker image
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM