MCPcopy Index your code
hub / github.com/docker/cli / newCommitCommand

Function newCommitCommand

cli/command/container/commit.go:28–70  ·  view source on GitHub ↗

newCommitCommand creates a new cobra.Command for `docker commit`

(dockerCLI command.Cli)

Source from the content-addressed store, hash-verified

26
27// newCommitCommand creates a new cobra.Command for `docker commit`
28func newCommitCommand(dockerCLI command.Cli) *cobra.Command {
29 var options commitOptions
30
31 cmd := &cobra.Command{
32 Use: "commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]",
33 Short: "Create a new image from a container's changes",
34 Args: cli.RequiresRangeArgs(1, 2),
35 RunE: func(cmd *cobra.Command, args []string) error {
36 options.container = args[0]
37 if len(args) > 1 {
38 options.reference = args[1]
39 }
40 if cmd.Flag("pause").Changed {
41 if cmd.Flag("no-pause").Changed {
42 return errors.New("conflicting options: --no-pause and --pause cannot be used together")
43 }
44 options.noPause = !options.pause
45 }
46 return runCommit(cmd.Context(), dockerCLI, &options)
47 },
48 Annotations: map[string]string{
49 "aliases": "docker container commit, docker commit",
50 },
51 ValidArgsFunction: completion.ContainerNames(dockerCLI, false),
52 DisableFlagsInUseLine: true,
53 }
54
55 flags := cmd.Flags()
56 flags.SetInterspersed(false)
57
58 // TODO(thaJeztah): Deprecated: the --pause flag was deprecated in v29 and can be removed in v30.
59 flags.BoolVarP(&options.pause, "pause", "p", true, "Pause container during commit (deprecated: use --no-pause instead)")
60 _ = flags.MarkDeprecated("pause", "and enabled by default. Use --no-pause to disable pausing during commit.")
61
62 flags.BoolVar(&options.noPause, "no-pause", false, "Disable pausing container during commit")
63 flags.StringVarP(&options.comment, "message", "m", "", "Commit message")
64 flags.StringVarP(&options.author, "author", "a", "", `Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")`)
65
66 options.changes = opts.NewListOpts(nil)
67 flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
68
69 return cmd
70}
71
72func runCommit(ctx context.Context, dockerCli command.Cli, options *commitOptions) error {
73 response, err := dockerCli.Client().ContainerCommit(ctx, options.container, client.ContainerCommitOptions{

Callers 3

newContainerCommandFunction · 0.85
TestRunCommitFunction · 0.85
TestRunCommitClientErrorFunction · 0.85

Calls 1

runCommitFunction · 0.85

Tested by 2

TestRunCommitFunction · 0.68
TestRunCommitClientErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…