validating ...\compose.yaml: services.web.healthcheck.interval must be a string — the value is a bare number, interval: 10, and Compose wants a duration written as text with a unit, such as 10s. Add the unit and the file validates.

Write interval: 10s. The same message appeared for stop_grace_period: 10 and for build given a list, each with its own path in front.

The error

PS> docker compose -p fix10-cs-p6 config
validating C:\...\p6\compose.yaml: services.web.healthcheck.interval must be a string

The command exited with code 1. The path to the test folder is shortened; nothing else in the line was changed. The file:

services:
  web:
    image: alpine
    command: ["echo", "hello"]
    healthcheck:
      test: ["CMD", "true"]
      interval: 10

Why it happens

YAML reads 10 without quotes as a number. Compose's check of the file wants a string for healthcheck.interval, and the path in the message, services.web.healthcheck.interval, points at the value it refused. The message says nothing about units, but the fix below shows that the string it wants is a number followed by one, as in 10s.

Two more files gave the same wording at other paths. A grace period written as a number:

    stop_grace_period: 10
validating C:\...\pd\compose.yaml: services.web.stop_grace_period must be a string

And build given a list of two values:

services:
  web:
    build: [".", "Dockerfile"]
validating C:\...\pe\compose.yaml: services.web.build must be a string

For build, both build: . and the long form with context: . and dockerfile: Dockerfile under build: passed docker compose config --quiet with exit code 0.

The fix

services:
  web:
    image: alpine
    command: ["echo", "hello"]
    healthcheck:
      test: ["CMD", "true"]
      interval: 10s
PS> docker compose -p fix10-cs-p6 config
name: fix10-cs-p6
services:
  web:
...
    healthcheck:
      test:
        - CMD
        - "true"
      interval: 10s
...

With the unit added the file validated, and config printed the interval as 10s. The values 10x and 10 seconds printed a different message, time: unknown unit; that one has its own post, linked below.

How it was reproduced

One-service files checked with docker compose config from Windows PowerShell 5.1: two alpine services with interval: 10 under healthcheck and with stop_grace_period: 10, a service with only build: [".", "Dockerfile"], an alpine service with interval: 10 seconds, then the healthcheck file with interval: 10s and the two build forms with config --quiet. Docker Compose v5.7.0, Docker Engine 29.9.3, Docker Desktop 4.99.0 on Windows (version 10.0.26300). Nothing was started; the project names with fix10-cs- are this test's own.

Frequently asked

What does 'healthcheck.interval must be a string' mean in docker compose?
The interval is written as a bare number such as 10, which YAML reads as a number. Compose wants a duration with a unit, such as 10s.
What format does a Docker Compose healthcheck interval use?
A number followed by a unit, for example 10s. In this test interval: 10s validated and interval: 10 gave the must be a string error.
Why does 'build must be a string' appear when I give build a list?
A list of two values was refused with services.web.build must be a string in this test. Give build the context as a string, such as build: ., or use the long form with context: under build:.

More decoded errors in the Fixes category. For a unit Compose does not accept, see Docker Compose: time: unknown unit in duration.