docker/compose · error

could not get created time for service's image

Error message

could not get created time for service's image

What it means

In `docker compose watch`, Compose looks up the service's running container to inspect its image creation time (used to detect stale images needing rebuild). This error is returned when `ContainerList` with the project + service label filters returns zero containers — the service is not running.

Source

Thrown at pkg/compose/watch.go:859

}

func shouldIgnore(name string, ignore watch.PathMatcher) bool {
	shouldIgnore, _ := ignore.Matches(name)
	// ignore files that match any ignore pattern
	return shouldIgnore
}

// gets the image creation time for a service
func (s *composeService) imageCreatedTime(ctx context.Context, project *types.Project, serviceName string) (time.Time, error) {
	res, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{
		All:     true,
		Filters: projectFilter(project.Name).Add("label", serviceFilter(serviceName)),
	})
	if err != nil {
		return time.Now(), err
	}
	if len(res.Items) == 0 {
		return time.Now(), fmt.Errorf("could not get created time for service's image")
	}

	img, err := s.apiClient().ImageInspect(ctx, res.Items[0].ImageID)
	if err != nil {
		return time.Now(), err
	}
	// Need to get the oldest one?
	timeCreated, err := time.Parse(time.RFC3339Nano, img.Created)
	if err != nil {
		return time.Now(), err
	}
	return timeCreated, nil
}

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. Start the project first: `docker compose up -d` then `docker compose watch`
  2. Verify the service has a container: `docker compose ps` and check the project/service labels
  3. Ensure `COMPOSE_PROJECT_NAME` / working directory match the ones used to create the containers
Defensive patterns

Strategy: validation

Validate before calling

# ensure the service is up before watching
docker compose up -d && docker compose ps --status running | grep -q "<service>" && docker compose watch

Prevention

When it happens

Trigger: Calling the watch path (`compose watch` / `up --watch`) for a service that has no containers: never started, already removed with `down`, or the project name label doesn't match. Note the function returns `time.Now()` alongside the error, and callers may ignore it.

Common situations: Running `docker compose watch` without `up` first (older flows), a container that crashed and exited between listing attempts, mismatched `COMPOSE_PROJECT_NAME`, or containers created by a different Compose version with different labels.

Related errors


AI-assisted analysis of docker/compose@ddc4b044b6 (2026-08-15). Data as JSON: /api/errors/280ba341cb07ecb9. Report an issue: GitHub.