docker/cli ยท error

failed to rename container: %w

Error message

failed to rename container: %w

What it means

Error "failed to rename container: %w" thrown in docker/cli.

Source

Thrown at cli/command/container/rename.go:25

	"github.com/docker/cli/cli/command"
	"github.com/docker/cli/cli/command/completion"
	"github.com/moby/moby/client"
	"github.com/spf13/cobra"
)

// newRenameCommand creates a new cobra.Command for "docker container rename".
func newRenameCommand(dockerCLI command.Cli) *cobra.Command {
	cmd := &cobra.Command{
		Use:   "rename CONTAINER NEW_NAME",
		Short: "Rename a container",
		Args:  cli.ExactArgs(2),
		RunE: func(cmd *cobra.Command, args []string) error {
			oldName, newName := args[0], args[1]
			_, err := dockerCLI.Client().ContainerRename(cmd.Context(), oldName, client.ContainerRenameOptions{
				NewName: newName,
			})
			if err != nil {
				return fmt.Errorf("failed to rename container: %w", err)
			}
			return nil
		},
		Annotations: map[string]string{
			"aliases": "docker container rename, docker rename",
		},
		ValidArgsFunction:     completion.ContainerNames(dockerCLI, true),
		DisableFlagsInUseLine: true,
	}
	return cmd
}

View on GitHub (pinned to e9452d6e78)

When it happens

Trigger: Thrown at cli/command/container/rename.go:25 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/949bb3fefbd5426f.json. Report an issue: GitHub.