go-containerregistry:crane 使用说明:docker 镜像操作神器

安装

github 下载安装

  1. 下载 Releases · google/go-containerregistry · GitHub 中合适的 CPU 架构
  2. 解压后,将二进制放在 /usr/local/bin/ 文件夹即可

基于 go 安装

如果提示 verifying module: missing GOSUMDB,可以先执行 export GOSUMDB=off

go install github.com/google/go-containerregistry/cmd/crane@latest

安装位置

~/go/bin/crane

帮助文档

root@pi:~/go-containerregistry# ./crane --help
Crane is a tool for managing container images

Usage:
  crane [flags]
  crane [command]

Available Commands:
  append      Append contents of a tarball to a remote image
  auth        Log in or access credentials
  blob        Read a blob from the registry
  catalog     List the repos in a registry
  completion  Generate the autocompletion script for the specified shell
  config      Get the config of an image
  copy        Efficiently copy a remote image from src to dst while retaining the digest value
  delete      Delete an image reference from its registry
  digest      Get the digest of an image
  export      Export filesystem of a container image as a tarball
  flatten     Flatten an image's layers into a single layer
  help        Help about any command
  index       Modify an image index.
  ls          List the tags in a repo
  manifest    Get the manifest of an image
  mutate      Modify image labels and annotations. The container must be pushed to a registry, and the manifest is updated there.
  pull        Pull remote images by reference and store their contents locally
  push        Push local image contents to a remote registry
  rebase      Rebase an image onto a new base image
  registry    
  tag         Efficiently tag a remote image
  validate    Validate that an image is well-formed
  version     Print the version

Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
  -h, --help                               help for crane
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs

Use "crane [command] --help" for more information about a command.
root@pi:~/go-containerregistry#

completion 为指定的 shell 生成自动补全脚本

帮助文档

root@pi:~/go-containerregistry# ./crane completion --help
Generate the autocompletion script for crane for the specified shell.
See each sub-command's help for details on how to use the generated script.

Usage:
  crane completion [command]

Available Commands:
  bash        Generate the autocompletion script for bash
  fish        Generate the autocompletion script for fish
  powershell  Generate the autocompletion script for powershell
  zsh         Generate the autocompletion script for zsh

Flags:
  -h, --help   help for completion

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs

Use "crane completion [command] --help" for more information about a command.
root@pi:~/go-containerregistry# 

bash 使用方式

重新连接,即可使用 tab 自动补全脚本

./crane completion bash > /etc/bash_completion.d/crane

auth 登录

帮助文档

root@pi:~/go-containerregistry# ./crane auth --help
Log in or access credentials

Usage:
  crane auth [flags]
  crane auth [command]

Available Commands:
  get         Implements a credential helper
  login       Log in to a registry
  logout      Log out of a registry
  token       Retrieves a token for a remote repo

Flags:
  -h, --help   help for auth

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs

Use "crane auth [command] --help" for more information about a command.
root@pi:~/go-containerregistry# ./crane auth get --help
Implements a credential helper

Usage:
  crane auth get [REGISTRY_ADDR] [flags]

Examples:
  # Read configured credentials for reg.example.com
  $ echo "reg.example.com" | crane auth get
  {"Username":"AzureDiamond","Secret":"hunter2"}
  # or
  $ crane auth get reg.example.com
  {"Username":"AzureDiamond","Secret":"hunter2"}

Flags:
  -h, --help   help for get

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# ./crane auth login --help
Log in to a registry

Usage:
  crane auth login [OPTIONS] [SERVER] [flags]

Examples:
  # Log in to reg.example.com
  crane auth login reg.example.com -u AzureDiamond -p hunter2

Flags:
  -h, --help              help for login
  -p, --password string   Password
      --password-stdin    Take the password from stdin
  -u, --username string   Username

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# ./crane auth logout --help
Log out of a registry

Usage:
  crane auth logout [SERVER] [flags]

Examples:
  # Log out of reg.example.com
  crane auth logout reg.example.com

Flags:
  -h, --help   help for logout

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# ./crane auth token --help
Retrieves a token for a remote repo

Usage:
  crane auth token REPO [flags]

Examples:
# If you wanted to mount a blob from debian to ubuntu.
$ curl -H "$(crane auth token -H --push --mount debian ubuntu)" ...

# To get the raw list tags response
$ curl -H "$(crane auth token -H ubuntu)" https://index.docker.io/v2/library/ubuntu/tags/list


Flags:
  -H, --header          Output in header format
  -h, --help            help for token
  -m, --mount strings   Scopes to mount from
      --push            Request push scopes

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# 

示例

$u:环境变量

$p:环境变量

root@pi:~/go-containerregistry# ./crane auth logout registry.cn-qingdao.aliyuncs.com
2026/08/05 16:50:08 logged out via /root/.docker/config.json
root@pi:~/go-containerregistry# ./crane auth login registry.cn-qingdao.aliyuncs.com -u $u -p $p

WARNING! Your credentials are stored unencrypted in '/root/.docker/config.json'.
Configure a credential helper to remove this warning. See
https://docs.docker.com/go/credential-store/

2026/08/05 16:50:50 logged in via /root/.docker/config.json
root@pi:~/go-containerregistry#

config 获取镜像的配置

帮助文档

root@pi:~/go-containerregistry# ./crane config --help
Get the config of an image

Usage:
  crane config IMAGE [flags]

Flags:
  -h, --help   help for config

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# 

示例

root@pi:~/go-containerregistry# ./crane config registry.openanolis.cn/openanolis/anolisos:23.5 | jq
{
  "architecture": "amd64",
  "config": {
    "Env": [
      "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
      "TZ=Asia/Shanghai"
    ],
    "Cmd": [
      "/bin/bash"
    ],
    "WorkingDir": "/",
    "Labels": {
      "maintainer": "OpenAnolis Cloud Native SIG",
      "org.opencontainers.image.created": "2026-01-07",
      "org.opencontainers.image.licenses": "Mulan PSL v2",
      "org.opencontainers.image.title": "Anolis OS Base Image",
      "org.opencontainers.image.vendor": "Anolis OS 23.5"
    },
    "ArgsEscaped": true
  },
  "created": "2026-07-22T01:59:07.664999389Z",
  "history": [
    {
      "created": "2026-07-22T01:58:58.133133805Z",
      "created_by": "LABEL org.opencontainers.image.title=Anolis OS Base Image org.opencontainers.image.vendor=Anolis OS 23.5 org.opencontainers.image.licenses=Mulan PSL v2 org.opencontainers.image.created=2026-01-07 maintainer=OpenAnolis Cloud Native SIG",
      "comment": "buildkit.dockerfile.v0",
      "empty_layer": true
    },
    {
      "created": "2026-07-22T01:58:58.133133805Z",
      "created_by": "ARG TARGETARCH=amd64",
      "comment": "buildkit.dockerfile.v0",
      "empty_layer": true
    },
    {
      "created": "2026-07-22T01:58:58.133133805Z",
      "created_by": "ADD AnolisOS-23.5-docker-amd64.tar / # buildkit",
      "comment": "buildkit.dockerfile.v0"
    },
    {
      "created": "2026-07-22T01:59:07.664999389Z",
      "created_by": "RUN |1 TARGETARCH=amd64 /bin/sh -c ln -sf /usr/share/zoneinfo/UTC /etc/localtime && echo Asia/Shanghai > /etc/timezone # buildkit",
      "comment": "buildkit.dockerfile.v0"
    },
    {
      "created": "2026-07-22T01:59:07.664999389Z",
      "created_by": "ENV TZ=Asia/Shanghai",
      "comment": "buildkit.dockerfile.v0",
      "empty_layer": true
    },
    {
      "created": "2026-07-22T01:59:07.664999389Z",
      "created_by": "CMD [\"/bin/bash\"]",
      "comment": "buildkit.dockerfile.v0",
      "empty_layer": true
    }
  ],
  "os": "linux",
  "rootfs": {
    "type": "layers",
    "diff_ids": [
      "sha256:6d844688b164927800163c4ea95875383018569fac35e9702b950db58edf419a",
      "sha256:67df7e2afbcae96430326d29bc197633817c625facb140f071eb77425eaccb0a"
    ]
  }
}
root@pi:~/go-containerregistry# 

copy 远程镜像复制

帮助文档

root@pi:~/go-containerregistry# ./crane copy --help
Efficiently copy a remote image from src to dst while retaining the digest value

Usage:
  crane copy SRC DST [flags]

Aliases:
  copy, cp

Flags:
  -a, --all-tags     (Optional) if true, copy all tags from SRC to DST
  -h, --help         help for copy
  -j, --jobs int     (Optional) The maximum number of concurrent copies, defaults to GOMAXPROCS
  -n, --no-clobber   (Optional) if true, avoid overwriting existing tags in DST

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry#

使用示例

ls:查看远端仓库镜像标签

root@pi:~/go-containerregistry# ./crane ls registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java
0.0.1-SNAPSHOT
0.0.1-SNAPSHOT-22
0.0.1-SNAPSHOT-22-amd64
0.0.1-SNAPSHOT-22-arm64
0.0.1-SNAPSHOT-22-loong64
0.0.1-SNAPSHOT-23
0.0.1-SNAPSHOT-23-amd64
0.0.1-SNAPSHOT-23-arm64
0.0.1-SNAPSHOT-23-loong64
0.0.1-SNAPSHOT-24
0.0.1-SNAPSHOT-24-amd64
0.0.1-SNAPSHOT-24-arm64
0.0.1-SNAPSHOT-24-loong64
0.0.1-SNAPSHOT-amd64
0.0.1-SNAPSHOT-arm64
0.0.1-SNAPSHOT-loong64
root@pi:~/go-containerregistry# ./crane ls registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak
Error: reading tags for registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak: GET https://registry.cn-qingdao.aliyuncs.com/v2/xuxiaoweicomcn/java-bak/tags/list?n=1000: NAME_UNKNOWN: repository name not known to registry; map[name:xuxiaoweicomcn/java-bak]
root@pi:~/go-containerregistry# ./crane cp registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java:0.0.1-SNAPSHOT-24 registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak:0.0.1-SNAPSHOT-24
2026/08/05 18:49:06 Copying from registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java:0.0.1-SNAPSHOT-24 to registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak:0.0.1-SNAPSHOT-24
2026/08/05 18:49:08 mounted blob: sha256:4609f7257f94aa162ecf692e7cf58f07e9a4ff8d3d69310e4bdf5584ff5a9c8b
2026/08/05 18:49:08 mounted blob: sha256:b3a02b8aedc37281189ac09372dd59948f4272ec209587f6255469c9135e43d1
2026/08/05 18:49:08 mounted blob: sha256:144439eda152fb76587e5057a89e2f331d64c38e0ff745d24df3358debd5ced4
2026/08/05 18:49:08 mounted blob: sha256:d9def6a050cba6f3553605e3193a2eced16e6986074396f44f4cfac71d5667e6
2026/08/05 18:49:08 mounted blob: sha256:69a96f320a22af2af264359f160768beb81380a75f0b86f96df773a2acfbdb95
2026/08/05 18:49:08 mounted blob: sha256:d74bca6ebb07f167419945f6c687b35d5992d7200ce841032e9de35fe5a9b07c
2026/08/05 18:49:08 mounted blob: sha256:2ae875dfbdcfbdcf34977208a0f5487eb4122afd6054208921b891a09db07fb4
2026/08/05 18:49:08 mounted blob: sha256:54273d8675f329a1fbcaa73525f4338987bd8e81ba06b9ba72ed9ca63246c834
2026/08/05 18:49:08 mounted blob: sha256:a8a2b9641e4b47aa1cb0cd5d071edb01f0b2c757911dd9034eaf2d7f03da5078
2026/08/05 18:49:08 mounted blob: sha256:8326e68752d6af70f273594bea724d77e98bdfbff2440cb5243bcbba80c705e0
2026/08/05 18:49:08 mounted blob: sha256:215bcbbef802ae2bbbe2d2ceeb76a3136e60e1402d5e7a20df0d9690bea1e848
2026/08/05 18:49:08 mounted blob: sha256:bcb402bc9e643bf0d2d7cf123580936458171aaa6a6ce44e2e3736dae3819302
2026/08/05 18:49:08 mounted blob: sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1
2026/08/05 18:49:08 mounted blob: sha256:3ff98681644b92e75a7c4f24833398074bad6a09da2d42bf96f04d651671f6dc
2026/08/05 18:49:08 mounted blob: sha256:aa1a14361c5adb0f25cfa5a1b9acdd4ff92dffb3ddad21ccdc7181f25690e10c
2026/08/05 18:49:08 mounted blob: sha256:1f6c938b750292152f46388e7d9072561fd19179ab123c56704ba2fc58dc8417
2026/08/05 18:49:08 mounted blob: sha256:108696236f4a847029ba00d3d42f2872ed5dc56e54c2568f35674d10b8370869
2026/08/05 18:49:08 mounted blob: sha256:befd8c19a1c231fb1c39090dccb9b050d9a2e5913171d90fba04f9f30706fa88
2026/08/05 18:49:08 mounted blob: sha256:147f37f2ed0bec2bf95ce8bc76533be421d068df08663813eac724f160a8aac4
2026/08/05 18:49:08 registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak@sha256:84129a5c1823b6b2d9d7df6175117fe55c30e362a02c673ea87e19181ee23d33: digest: sha256:84129a5c1823b6b2d9d7df6175117fe55c30e362a02c673ea87e19181ee23d33 size: 1402
2026/08/05 18:49:08 registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak@sha256:093b942af8b96ceeb5cb5e3799ad6fcd4d7c74aef85297198246be86df686898: digest: sha256:093b942af8b96ceeb5cb5e3799ad6fcd4d7c74aef85297198246be86df686898 size: 1726
2026/08/05 18:49:08 registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak@sha256:353bf24ee3c12d19ac6075e73b8b20bf26e26b279e85b6de2fdcb390f934917b: digest: sha256:353bf24ee3c12d19ac6075e73b8b20bf26e26b279e85b6de2fdcb390f934917b size: 1726
2026/08/05 18:49:08 registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak:0.0.1-SNAPSHOT-24: digest: sha256:d92c4378d3b6ac5134ce6832dc80abd17824684d53638838df98b09b3a91a75c size: 920
root@pi:~/go-containerregistry# ./crane ls registry.cn-qingdao.aliyuncs.com/xuxiaoweicomcn/java-bak
0.0.1-SNAPSHOT-24
root@pi:~/go-containerregistry#

delete 删除远端仓库镜像

帮助文档

root@hk-2:~/go-containerregistry# ./crane delete --help
Delete an image reference from its registry

Usage:
  crane delete IMAGE [flags]

Flags:
  -h, --help   help for delete

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@hk-2:~/go-containerregistry# 

示例

ls:查看远端仓库镜像标签

root@hk-2:~/go-containerregistry# ./crane ls xuxiaoweicomcn/nginx
1.30.0
1.31.0
1.31.1
root@hk-2:~/go-containerregistry# ./crane delete xuxiaoweicomcn/nginx:1.30.0
root@hk-2:~/go-containerregistry# ./crane ls xuxiaoweicomcn/nginx
1.31.0
1.31.1
root@hk-2:~/go-containerregistry# 

export 导出镜像的文件系统

帮助文档

root@pi:~/go-containerregistry# ./crane export --help 
Export filesystem of a container image as a tarball

Usage:
  crane export IMAGE|- TARBALL|- [flags]

Examples:
  # Write tarball to stdout
  crane export ubuntu -

  # Write tarball to file
  crane export ubuntu ubuntu.tar

  # Read image from stdin
  crane export - ubuntu.tar

Flags:
  -h, --help   help for export

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# 

示例

./crane export --platform=linux/amd64 registry.openanolis.cn/openanolis/anolisos:23.5 anolisos-23.5-amd64.tar
./crane export --platform=linux/arm64 registry.openanolis.cn/openanolis/anolisos:23.5 anolisos-23.5-arm64.tar

ls 列出仓库中的标签

帮助文档

root@pi:~/go-containerregistry# ./crane ls --help
List the tags in a repo

Usage:
  crane ls REPO [flags]

Flags:
      --full-ref           (Optional) if true, print the full image reference
  -h, --help               help for ls
  -O, --omit-digest-tags   (Optional), if true, omit digest tags (e.g., ':sha256-...')

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry#

示例

root@pi:~/go-containerregistry# ./crane ls registry.openanolis.cn/openanolis/anolisos
23-20230704
23-busybox-20230711
23-busybox
23-micro-20230711
23-micro
23-minimal-20230711
23-minimal
23.1
23.2
23.3
23.4
23.5
23
8-nydus
8.10
8.6-230310.1
8.6-230315.1
8.6
8.8-230324.1-nydus
8.8-230324.1
8.8-nydus
8.8
8.9
8
latest-nydus
latest
root@pi:~/go-containerregistry# 

manifest 获取镜像的清单

帮助文档

root@pi:~/go-containerregistry# ./crane manifest --help
Get the manifest of an image

Usage:
  crane manifest IMAGE [flags]

Flags:
  -h, --help   help for manifest

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# 

示例

root@pi:~/go-containerregistry# ./crane manifest registry.openanolis.cn/openanolis/anolisos:23.5
{
  "schemaVersion": 2,
  "mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
  "manifests": [
    {
      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
      "digest": "sha256:9ba059e7e78d033873eed844190da91db6c462e4ec2a76bf77d85649b8218bcf",
      "size": 698,
      "platform": {
        "architecture": "amd64",
        "os": "linux"
      }
    },
    {
      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
      "digest": "sha256:044ffd6bd183f757a7ec4c6dd5513b39a3e128927d902070cf501db406b6ff87",
      "size": 698,
      "platform": {
        "architecture": "arm64",
        "os": "linux"
      }
    }
  ]
}root@pi:~/go-containerregistry# 

pull 拉取镜像保存为文件

帮助文档

./crane pull --help
root@pi:~/go-containerregistry# ./crane pull --help
Pull remote images by reference and store their contents locally

Usage:
  crane pull IMAGE TARBALL [flags]

Flags:
      --annotate-ref        Preserves image reference used to pull as an annotation when used with --format=oci
  -c, --cache_path string   Path to cache image layers
      --format string       Format in which to save images ("tarball", "legacy", or "oci") (default "tarball")
  -h, --help                help for pull

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# 

示例

./crane pull --platform=linux/amd64 registry.openanolis.cn/openanolis/anolisos:23.5 anolisos-23.5-amd64.tar
./crane pull --platform=linux/arm64 registry.openanolis.cn/openanolis/anolisos:23.5 anolisos-23.5-arm64.tar

检查拉取结果

root@pi:~/go-containerregistry# tar -xOf anolisos-23.5-amd64.tar $(tar -xOf anolisos-23.5-amd64.tar manifest.json | jq -r '.[0].Config') | jq '{os, architecture}'
{
  "os": "linux",
  "architecture": "amd64"
}
root@pi:~/go-containerregistry# tar -xOf anolisos-23.5-arm64.tar $(tar -xOf anolisos-23.5-arm64.tar manifest.json | jq -r '.[0].Config') | jq '{os, architecture}'
{
  "os": "linux",
  "architecture": "arm64"
}
root@pi:~/go-containerregistry# 

rebase 修改镜像的基础镜像

帮助文档

root@pi:~/go-containerregistry# ./crane rebase --help
Rebase an image onto a new base image

Usage:
  crane rebase [flags]

Flags:
  -h, --help              help for rebase
      --new_base string   New base image to insert
      --old_base string   Old base image to remove
      --original string   Original image to rebase (DEPRECATED: use positional arg instead)
      --rebased string    Tag to apply to rebased image (DEPRECATED: use --tag)
  -t, --tag string        Tag to apply to rebased image

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# 

tag 标记远程镜像标签

帮助文档

root@pi:~/go-containerregistry# ./crane tag --help
Tag remote image without downloading it.

This differs slightly from the "copy" command in a couple subtle ways:

1. You don't have to specify the entire repository for the tag you're adding. For example, these two commands are functionally equivalent:
```
crane cp registry.example.com/library/ubuntu:v0 registry.example.com/library/ubuntu:v1
crane tag registry.example.com/library/ubuntu:v0 v1
```

3. We can skip layer existence checks because we know the manifest already exists. This makes "tag" slightly faster than "copy".

Usage:
  crane tag IMG TAG [flags]

Examples:
# Add a v1 tag to ubuntu
crane tag ubuntu v1

Flags:
  -h, --help   help for tag

Global Flags:
      --allow-nondistributable-artifacts   Allow pushing non-distributable (foreign) layers
      --insecure                           Allow image references to be fetched without TLS
      --platform platform                  Specifies the platform in the form os/arch[/variant][:osversion] (e.g. linux/amd64). (default all)
  -v, --verbose                            Enable debug logs
root@pi:~/go-containerregistry# 

示例

ls:查看远端仓库镜像标签

./crane tag xuxiaoweicomcn/nginx:1.31.1-amd64 1.31.1-amd64-bak
root@hk-2:~/go-containerregistry# ./crane ls xuxiaoweicomcn/nginx
1.31.1-amd64
root@hk-2:~/go-containerregistry# ./crane tag xuxiaoweicomcn/nginx:1.31.1-amd64 1.31.1-amd64-bak
2026/08/05 18:40:50 index.docker.io/xuxiaoweicomcn/nginx:1.31.1-amd64-bak: digest: sha256:4a2d27f57e72adbc1e1cfed8db6cbdef22c080e058565f92647f7aad258292f2 size: 2290
root@hk-2:~/go-containerregistry# ./crane ls xuxiaoweicomcn/nginx
1.31.1-amd64
1.31.1-amd64-bak
root@hk-2:~/go-containerregistry#

version 查看版本

./crane version
root@pi:~/go-containerregistry# ./crane version
0.21.8
root@pi:~/go-containerregistry# 

手动同步镜像对比

root@hk-2:~# docker pull nginx:1.29.0
1.29.0: Pulling from library/nginx
856c000ad0ec: Pull complete 
85003794a6a5: Pull complete 
dea1652b095a: Pull complete 
9dbfe0b105c9: Pull complete 
fea7cebc499c: Pull complete 
b1badc6e5066: Pull complete 
c5ada5e7d698: Pull complete 
946b359b3ef2: Download complete 
23dc44e5f024: Download complete 
Digest: sha256:3ab4ed065a1437cbbd45e65617b1285bdf6523c6bf56a121e00df41720e09a89
Status: Downloaded newer image for nginx:1.29.0
docker.io/library/nginx:1.29.0
root@hk-2:~# 
root@hk-2:~# docker tag nginx:1.29.0 xuxiaoweicomcn/nginx:1.29.0
root@hk-2:~# 
root@hk-2:~# docker push xuxiaoweicomcn/nginx:1.29.0
The push refers to repository [docker.io/xuxiaoweicomcn/nginx]
856c000ad0ec: Mounted from library/nginx 
9dbfe0b105c9: Mounted from library/nginx 
b1badc6e5066: Mounted from library/nginx 
c5ada5e7d698: Mounted from library/nginx 
85003794a6a5: Mounted from library/nginx 
fea7cebc499c: Mounted from library/nginx 
dea1652b095a: Mounted from library/nginx 
1.29.0: digest: sha256:8e02d8ee403bdfe5cca7dc90276bf0f7c01080f1013d654de6a1357329bc711f size: 2292

i Info → Not all multiplatform-content is present and only the available single-platform image was pushed
         sha256:3ab4ed065a1437cbbd45e65617b1285bdf6523c6bf56a121e00df41720e09a89 -> sha256:8e02d8ee403bdfe5cca7dc90276bf0f7c01080f1013d654de6a1357329bc711f
root@hk-2:~#