In a GitHub Actions job that uses a PostgreSQL service container, how does the job connect to the database?
Select an answer to reveal the explanation.
Short Explanation
When your job runs in a container, use the service name as hostname. When steps run directly on the runner, use localhost.
Full Explanation
GitHub Actions service containers behave differently depending on the job configuration: If the job has a 'container:' block (steps run in a container), service containers are on the same Docker network and reachable by their service name (e.g., 'postgres'). If the job runs directly on the runner (no container: block), service containers are mapped to localhost with the specified port. GitHub does not inject connection strings as secrets — you manually set the appropriate host in your test configuration. The runner's public IP is not used for service communication.