[英]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.