Services name resolution error

I’m running into issues connecting to a Postgres service. My service file looks like this:

postgres:
        image: postgres:11
        ports:
          - 5432:5432
        env:
          POSTGRES_PASSWORD: "some_pass"
          POSTGRES_DB: "some_db"
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

My code is configured to talk to postgres when connecting to the database, but I’m getting the following error:

could not translate host name "postgres" to address: Temporary failure in name resolution

This reads like it’s unable to resolve “postgres” to anything useful. I’ve tried switching it to “database” and “my_database” (trying something non-generic) and everything gets the same issue. When I look at the container initialization, it seems like its doing the right thing (pulled and formatted from the logs):

/usr/bin/docker create --name << SOME HASH >>
--label dd9e73
--network github_network_<< HASH >>
--network-alias postgres
-p 5432:5432
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
-e "POSTGRES_PASSWORD=some_pass"
-e "POSTGRES_DB=some_db"
-e GITHUB_ACTIONS=true postgres:11

The one thing I’m not doing that all of the examples do is inject the database port. I’m not doing that based on the -p 5432:5432 option that’s being passed in. I also wouldn’t expect a port issue to be cropping up as a name resolution error.

Any ideas as to what I’m missing?

1 Like

Hey @tswicegood,

Thanks for being here and our apologies for the delayed response.  For investigation’s sake would you mind adding POSTGRES\_USER: postgres to your env in your service file?

Hey @andreagriffiths11 is there any updates on this?

Hey @andreagriffiths11 ,

Any update? I’m experiencing the same issue with mysql setup

name: CI

on:
  - push

jobs:
  test:
    runs-on: ubuntu-latest

    services:
      mysql:
        image: mysql:latest
        ports:
          - 3306
        env:
          MYSQL_USER: cishe
          MYSQL_PASSWORD: cishe
          # since github action for test only
          # we should make another file for other ci purpose
          MYSQL_DATABASE: cishe
          MYSQL_ROOT_PASSWORD: adminpwd
        options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 1
      - name: Verify MySQL connection
        run: |
          ping mysql -n 3
          echo ${{ job.services.mysql.ports['3306'] }}
          sudo apt-get install -y mysql-client
          mysql -hlocalhost -P${{ job.services.mysql.ports['3306'] }} -ucishe -pcishe -e "SHOW DATABASES"

and it failed with

ping: mysql: Temporary failure in name resolution
##[error]Process completed with exit code 2.

I found out what was the problem now!

It’s because of no jobs.<job_id>.container was specified. So my setup was running on a non-container env, therefore no name resolution for mysql

name: CI

on:
  - push

jobs:
  test:
    runs-on: ubuntu-latest
    container: python:3.8-alpine  # this line makes it running as a container job!!!
    services:
      mysql:
        image: mysql:latest
        ports:
          - 3306
        env:
          MYSQL_USER: cishe
          MYSQL_PASSWORD: cishe
          # since github action for test only
          # we should make another file for other ci purpose
          MYSQL_DATABASE: cishe
          MYSQL_ROOT_PASSWORD: adminpwd
        options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 1
      - name: Verify MySQL connection name resolution
        run: |
          ping mysql -n 3
          echo ${{ job.services.mysql.ports['3306'] }}

I think the way github actions doc describes, does not emphasize the difference about this.
Maybe a direct example code along the doc will do