{"record":{"id":"5aec35cfc1e48839","repo":"docker/compose","slug":"at-least-one-container-must-be-specified","errorCode":null,"errorMessage":"at least one container must be specified","messagePattern":"at least one container must be specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/compose/generate.go","lineNumber":61,"sourceCode":"\t\tShort: \"EXPERIMENTAL - Generate a Compose file from existing containers\",\n\t\tPreRunE: Adapt(func(ctx context.Context, args []string) error {\n\t\t\treturn nil\n\t\t}),\n\t\tRunE: Adapt(func(ctx context.Context, args []string) error {\n\t\t\treturn runGenerate(ctx, dockerCli, backendOptions, opts, args)\n\t\t}),\n\t}\n\n\tcmd.Flags().StringVar(&opts.ProjectName, \"name\", \"\", \"Project name to set in the Compose file\")\n\tcmd.Flags().StringVar(&opts.ProjectDir, \"project-dir\", \"\", \"Directory to use for the project\")\n\tcmd.Flags().StringVar(&opts.Format, \"format\", \"yaml\", \"Format the output. Values: [yaml | json]\")\n\treturn cmd\n}\n\nfunc runGenerate(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts generateOptions, containers []string) error {\n\t_, _ = fmt.Fprintln(os.Stderr, \"generate command is EXPERIMENTAL\")\n\tif len(containers) == 0 {\n\t\treturn fmt.Errorf(\"at least one container must be specified\")\n\t}\n\n\tbackend, err := compose.NewComposeService(dockerCli, backendOptions.Options...)\n\tif err != nil {\n\t\treturn err\n\t}\n\tproject, err := backend.Generate(ctx, api.GenerateOptions{\n\t\tContainers:  containers,\n\t\tProjectName: opts.ProjectName,\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar content []byte\n\tswitch opts.Format {\n\tcase \"json\":\n\t\tcontent, err = project.MarshalJSON()","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/docker/compose/blob/ddc4b044b62e9f715212ea4143fa830fac76382f/cmd/compose/generate.go#L43-L79","documentation":"The experimental `docker compose generate` command requires at least one existing container as input to derive a Compose file from. runGenerate checks len(containers) == 0 immediately after printing its experimental warning and refuses to continue.","triggerScenarios":"Running plain `docker compose generate` with no container IDs/names as positional arguments, or passing an empty string as the only argument which cobra may treat as zero valid args.","commonSituations":"Trying to generate a compose file from a stopped project's containers that were already removed; misunderstanding the command as 'generate from an image or from nothing'; empty `$(docker ps -q)` expansion in scripts.","solutions":["Pass one or more running container names/IDs: `docker compose generate my_container`.","Start the containers first (`docker compose up -d`) then run generate against them.","In scripts, check the container list is non-empty before invoking generate."],"exampleFix":"# before\ndocker compose generate\n\n# after\ndocker start my_container && docker compose generate my_container","handlingStrategy":"validation","validationCode":"# bash\n[ \"$#\" -ge 1 ] || { echo \"usage: compose generate CONTAINER [CONTAINER...]\" >&2; exit 2; }\ndocker compose generate \"$@\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check `docker ps` output is non-empty before generating from containers.","Remember generate is experimental — pin behavior with tests when you adopt it."],"tags":["cli","generate","experimental","arguments"],"backgroundTag":null,"analyzedSha":"ddc4b044b62e9f715212ea4143fa830fac76382f","analyzedAt":"2026-08-15T13:31:42.319Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}