'services[web].healthcheck.interval' time: unknown unit "x" in duration "10x" — a duration in the Compose file has a unit Compose does not accept. Write it as a number followed by a short unit such as s, for example 10s, with no space.

The quoted part after unknown unit is exactly what Compose could not read, spaces included. Replace the value at the path in front of the message, here healthcheck.interval, and run docker compose config again.

The error

PS> docker compose -p fix10-cs-p7 config
decoding failed due to the following error(s):

'services[web].healthcheck.interval' time: unknown unit "x" in duration "10x"

The command exited with code 1 and printed the blank line between the two lines of the message as shown. docker compose -p fix10-cs-p7 up on the same file printed the same three lines, exited with code 1 and created no container. The file:

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

Why it happens

10x is text, not a bare number, so it did not get the must be a string message that interval: 10 gets. It got this one instead: Compose read 10 as the amount and could not read x as a unit of time. The message starts with decoding failed rather than validating, and it writes the path as services[web] with the service name in brackets.

Writing the unit as a word gave the same message. With interval: 10 seconds the unknown unit was " seconds", with the leading space inside the quotes:

'services[web].healthcheck.interval' time: unknown unit " seconds" in duration "10 seconds"

In these tests both a made-up unit and a spelled-out English unit were refused, and the short form written straight after the number was accepted.

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
...

10s validated and config printed it unchanged. When the message names another path, the value to change is the one at that path; keep the unit next to the number there too.

How it was reproduced

One-service alpine files with a healthcheck, checked with docker compose config from Windows PowerShell 5.1: interval: 10x, interval: 10 seconds, and then interval: 10s; the 10x file was also passed to docker compose up, which stopped with the same message and created no container. Docker Compose v5.7.0, Docker Engine 29.9.3, Docker Desktop 4.99.0 on Windows (version 10.0.26300). The project names with fix10-cs- are this test's own.

Frequently asked

What does 'time: unknown unit in duration' mean in docker compose?
A duration in the file, such as a healthcheck interval, has a unit Compose cannot read. The quoted unit in the message is the part it rejected, for example x in 10x.
Can I write 10 seconds in a Docker Compose healthcheck?
No. In this test interval: 10 seconds was refused with unknown unit " seconds". Write 10s, with the unit straight after the number.
What is the difference between 'must be a string' and 'unknown unit' in Compose?
must be a string came from a bare number such as interval: 10. unknown unit came from a string with a unit Compose does not know, such as 10x. Both are fixed by writing 10s.

More decoded errors in the Fixes category. When the interval is a bare number such as 10, the message is different; see Docker Compose: healthcheck interval must be a string.