[英]Could not translate host name "postgres" to address on github actions
I'm configuring my first Github actions workflow.我正在配置我的第一个 Github 操作工作流。 It require postgres, so I added a service like this:
它需要 postgres,所以我添加了这样的服务:
services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: postgres_db
POSTGRES_PASSWORD: postgres_password
POSTGRES_PORT: 5432
POSTGRES_USER: postgres_user
ports:
- 5432:5432
# set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
But Github actions are unable to use the postgres
host.但是 Github 操作无法使用
postgres
主机。 There is the steps:有以下步骤:
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install PostgreSQL client
run: |
sudo apt-get update
sudo apt-get install --yes postgresql-client
- name: Test database connection
run: psql -h postgres -d postgres_db -U postgres_user -c 'SELECT 1;'
env:
PGPASSWORD: postgres_password
And the failure:而失败:
Run psql -h postgres -d postgres_db -U postgres_user -c 'SELECT 1;'
psql: error: could not translate host name "postgres" to address: Temporary failure in name resolution
Github action workflow page is available here: https://github.com/buxx/rolling/actions/runs/3092460076/jobs/5003751698 . Github 操作工作流程页面可在此处获得: https://github.com/buxx/rolling/actions/runs/3092460076/jobs/5003751698 。 And entire config file here: https://github.com/buxx/rolling/blob/3e4d200e5e111d3731d7fc8d18e5795a0b82ca9a/.github/workflows/pr-tests.yml
整个配置文件在这里: https://github.com/buxx/rolling/blob/3e4d200e5e111d3731d7fc8d18e5795a0b82ca9a/.github/workflows/pr-tests.yml
How to configure Github action workflow to be able to use postgresql service?如何配置 Github 操作工作流才能使用 postgresql 服务?
Without special indication about executing step into container, step is running on the runner.没有关于在容器中执行步骤的特殊指示,步骤正在运行器上运行。 So, postgres host to use is
localhost
.因此,要使用的 postgres 主机是
localhost
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.