{"record":{"id":"9efbb3b7a0343913","repo":"Billionmail/BillionMail","slug":"container-with-name-s-not-found","errorCode":null,"errorMessage":"container with name %s not found","messagePattern":"container with name (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/dockerapi/dockerapi.go","lineNumber":233,"sourceCode":"\t})\n}\n\n// GetContainerByName gets a container by its name\nfunc (d *DockerAPI) GetContainerByName(ctx context.Context, name string) (*container.Summary, error) {\n\targs := filters.NewArgs()\n\targs.Add(\"name\", name)\n\n\tcontainers, err := d.client.ContainerList(ctx, container.ListOptions{\n\t\tAll:     true,\n\t\tFilters: args,\n\t})\n\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif len(containers) == 0 {\n\t\treturn nil, fmt.Errorf(\"container with name %s not found\", name)\n\t}\n\n\treturn &containers[0], nil\n}\n\n// GetContainer gets container details\nfunc (d *DockerAPI) GetContainer(ctx context.Context, containerID string) (container.InspectResponse, error) {\n\treturn d.client.ContainerInspect(ctx, containerID)\n}\n\n// Close closes the Docker client connection\nfunc (d *DockerAPI) Close() error {\n\treturn d.client.Close()\n}\n\n// HostCommandResult stores the result of a command executed on the host\ntype HostCommandResult struct {\n\tExitCode int    `json:\"exit_code\"` // Command exit status code","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/dockerapi/dockerapi.go#L215-L251","documentation":"GetContainerByName lists Docker containers filtered by the given name and returns the first match. When the Docker list succeeds but returns zero containers, the name doesn't correspond to any existing container and this error is returned.","triggerScenarios":"Calling GetContainerByName (directly or via RestartContainerByName / ExecCommandByName) with a name that has no exact matching container; container filters applied in the underlying list exclude it.","commonSituations":"Typo in container name; container was removed/recreated with a different name; calling before docker-compose up; confusing container name with service name or with the auto-generated compose name (project_service_1).","solutions":["Run `docker ps --format '{{.Names}}'` to list exact container names and correct the name argument","Start the target container (docker compose up -d) before calling the API","Docker name filters are anchors — pass the full exact name, not a substring or the compose service name alone","Recreate the container if it was renamed during a redeploy"],"exampleFix":"// before\napi.ExecCommandByName(\"postfix\") // service name, not container name\n// after\napi.ExecCommandByName(\"billionmail-postfix\") // exact container name","handlingStrategy":"validation","validationCode":"func containerExists(ctx context.Context, cli *client.Client, name string) (bool, error) {\n    cs, err := cli.ContainerList(ctx, container.ListOptions{All: true,\n        Filters: filters.NewArgs(filters.Fany(\"name\", name))})\n    return len(cs) > 0, err\n}","typeGuard":"func hasContainer(r []*types.Container) bool { return len(r) > 0 }","tryCatchPattern":"out, err := api.ExecCommandByName(ctx, name, cmd)\nif err != nil && strings.Contains(err.Error(), \"not found\") {\n    log.Warnf(\"container %q missing, recreating...\", name)\n    return recreateContainer(name)\n}","preventionTips":["Use exact full container names (docker ps)","Verify containers exist after every redeploy","Don't confuse compose service names with container names","Check container is running, not just created"],"tags":["docker","container","not-found"],"backgroundTag":"container-not-found","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}