Interview Prep/GitHub Actions/Workflow Anatomy & Execution Model

What are service containers and how does networking differ between container jobs and host jobs?

IntermediateConceptWorkflow Anatomy & Execution Model
Answer

services start sidecar containers (databases, Redis) for the job, with health-checked startup via options.

services:
  postgres:
    image: postgres:16
    env: { POSTGRES_PASSWORD: test }
    ports: ["5432:5432"]
    options: >-
      --health-cmd "pg_isready -U postgres" --health-interval 5s --health-retries 10

If the job runs on the host, reach the service at localhost:5432 through the mapped port. If the job runs in a container, both share a Docker network and you use the service name: postgres:5432, no port mapping needed.

All GitHub Actions questions Roadmap: GitHub Actions

More on Workflow Anatomy & Execution Model