docker-run-action
docker-run-action copied to clipboard
Trying to access Postgres service from docker image
I'm trying to connect to Postgres db from within my Docker image to run tests:
test_backend:
runs-on:
group: ubuntu-large
needs: build_backend
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- name: Run tests in container
uses: addnab/docker-run-action@v3
with:
image: backend-py:${{github.sha}}
run: ./manage.py test --noinput
options: --env-file .github/workflows/env.test
There is a script, that tries to connect to Postgres running as a service. However I can't figure out, how to set the correct network/host value. I've tried to set in env.test
:
DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${INPUT_DOCKER_NETWORK}:5432/${POSTGRES_DB}
Which gives me error:
django.db.utils.OperationalError: could not translate host name "${input_docker_network}" to address: Name or service not known
How should I specify the host name to successfully connect to Postgres GitHub service?
If you haven't figured it out, or for others who come across this, the hostname here would just be postgres
, no other fancy docker networking necessary.