newImportCommand creates a new "docker image import" command.
(dockerCLI command.Cli)
| 26 | |
| 27 | // newImportCommand creates a new "docker image import" command. |
| 28 | func newImportCommand(dockerCLI command.Cli) *cobra.Command { |
| 29 | var options importOptions |
| 30 | |
| 31 | cmd := &cobra.Command{ |
| 32 | Use: "import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]", |
| 33 | Short: "Import the contents from a tarball to create a filesystem image", |
| 34 | Args: cli.RequiresMinArgs(1), |
| 35 | RunE: func(cmd *cobra.Command, args []string) error { |
| 36 | options.source = args[0] |
| 37 | if len(args) > 1 { |
| 38 | options.reference = args[1] |
| 39 | } |
| 40 | return runImport(cmd.Context(), dockerCLI, options) |
| 41 | }, |
| 42 | Annotations: map[string]string{ |
| 43 | "aliases": "docker image import, docker import", |
| 44 | }, |
| 45 | DisableFlagsInUseLine: true, |
| 46 | } |
| 47 | |
| 48 | flags := cmd.Flags() |
| 49 | |
| 50 | options.changes = dockeropts.NewListOpts(nil) |
| 51 | flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image") |
| 52 | flags.StringVarP(&options.message, "message", "m", "", "Set commit message for imported image") |
| 53 | flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable") |
| 54 | _ = flags.SetAnnotation("platform", "version", []string{"1.32"}) |
| 55 | _ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms()) |
| 56 | |
| 57 | return cmd |
| 58 | } |
| 59 | |
| 60 | func runImport(ctx context.Context, dockerCli command.Cli, options importOptions) error { |
| 61 | var source client.ImageImportSource |
searching dependent graphs…