You are adding integration tests to a YAML pipeline that runs on a Microsoft-hosted Ubuntu agent. The tests need a Redis instance, so you add a service container, as shown in the exhibit. The job has no container property and runs directly on the agent host.
resources:
containers:
- container: cache
image: redis
ports:
- 6379:6379
pool:
vmImage: 'ubuntu-latest'
services:
redis: cache
steps:
- script: ./run-integration-tests.sh --redis-host <HOST> --redis-port 6379
Which value should replace <HOST> so that the tests can reach Redis?
The job runs on the agent host, not in a container. In that case Azure Pipelines provides no automatic name resolution for service containers, and the job reaches them through localhost. Jobs on the host also need ports to reach the service container, and the 6379:6379 mapping exposes Redis on host port 6379. Service names such as redis resolve only from inside a job container on the shared Docker network.
- Not correct:
redis. Reaching a service by itsservicesname depends on Docker networking between the job container and the service containers. A job that runs on the host gets no automatic name resolution. - Correct:
localhost. In a noncontainer job, service containers are reached through localhost on the mapped host port. Here port 6379 on the host maps to the Redis container. - Not correct:
cache.cacheis the container resource name. A job that runs directly on the host gets no automatic name resolution for service containers, so this name does not resolve. - Not correct:
redis.cache. A job that runs directly on the host has no automatic name resolution for service containers, so no combined service or resource host name is provided.
- Service containers - Azure PipelinesMicrosoft Learn