docker/compose · error

no container(s) found with the following name(s): %s

Error message

no container(s) found with the following name(s): %s

What it means

'docker compose generate' builds a compose project from running containers, first resolving the requested container names/IDs. If the resulting set is empty after querying by name (and by IDs), it reports the joined list of names it could not find.

Source

Thrown at pkg/compose/generate.go:62

	containersByIds, err := s.apiClient().ContainerList(ctx, client.ContainerListOptions{
		Filters: make(client.Filters).Add("id", options.Containers...),
		All:     true,
	})
	if err != nil {
		return nil, err
	}

	for _, ctr := range containersByIds.Items {
		if !slices.ContainsFunc(containers, func(summary container.Summary) bool {
			return summary.ID == ctr.ID
		}) {
			containers = append(containers, ctr)
		}
	}

	if len(containers) == 0 {
		return nil, fmt.Errorf("no container(s) found with the following name(s): %s", strings.Join(options.Containers, ","))
	}

	return s.createProjectFromContainers(containers, options.ProjectName)
}

func (s *composeService) createProjectFromContainers(containers []container.Summary, projectName string) (*types.Project, error) {
	project := &types.Project{}
	services := types.Services{}
	networks := types.Networks{}
	volumes := types.Volumes{}
	secrets := types.Secrets{}

	if projectName != "" {
		project.Name = projectName
	}

	for _, c := range containers {
		// if the container is from a previous Compose application, use the existing service name

View on GitHub (pinned to ddc4b044b6)

Solutions

  1. List real names: docker ps -a --format '{{.Names}}' and retry with one of those
  2. Use the container ID instead of the name
  3. Verify the docker context matches where the containers run (docker context show)
  4. Start the container first if it exists but is stopped and you need it in the project

Example fix

# before
docker compose generate web        # actual name is demo-web-1
# after
docker compose generate demo-web-1
Defensive patterns

Strategy: validation

Validate before calling

// verify names resolve before calling Generate
res, err := cli.ContainerList(ctx, client.ContainerListOptions{All: true})
if err != nil { return err }
byName := map[string]bool{}
for _, c := range res { byName[c.Names[0][1:]] = true; byName[c.ID[0:12]] = true }
for _, n := range wanted { if !byName[n] { return fmt.Errorf("unknown container %s", n) } }

Prevention

When it happens

Trigger: docker compose generate <container...> where no listed name/ID matches a running or stopped container visible to the current docker context; containersByIds and name lookups both return nothing.

Common situations: Typo in container name; container removed or not yet started; wrong docker context; using compose service names instead of actual container names (e.g. missing project prefix like myproject-web-1).

Related errors


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