最近更新时间:2026-01-14 15:40:29
本文将介绍如何借助Skopeo工具,将其他云厂商镜像仓库(以阿里云镜像仓库ACR为例)中镜像迁移至KCR中。
Skopeo 是一个功能强大的容器镜像处理命令行工具。它允许用户在无需运行守护进程且无需root权限的情况下,对容器镜像执行多种关键操作。其核心能力在于能够在不同类型和位置的镜像存储库之间进行灵活的传输与检查。例如,它可以直接复制镜像(如在不同的容器镜像仓库、本地目录或容器存储之间同步),远程检查镜像的详细信息(如层、标签等)而无需拉取完整镜像,以及删除仓库中的镜像,这些特性使其成为容器运维、镜像仓库迁移和离线环境部署(如在内网同步外部仓库)的理想工具。
在金山云开启云服务器并安装 skopeo。以 Ubuntu 为例:
sudo apt update
sudo apt install skopeo -y其他系统请参考 Skopeo 官方文档。
登录阿里云控制台,在主账户创建个人版实例,并授予RAM用户(子账号)AliyunContainerRegistryFullAccess或AliyunContainerRegistryReadOnlyAccess的权限。
已设置Registry登录密码,创建镜像仓库并已经上传镜像。
登录金山云控制台,创建镜像仓库(以企业基础版为例)以及命名空间。
创建镜像仓库
点击实例进入详情,创建命名空间
在 实例管理 → 访问凭证 中创建访问凭证,并下载保存
mkdir -p ~/.dockeracr_registry="xxxx.cn-beijing.personal.cr.aliyuncs.com"
acr_username="<阿里云账号或者RAM前缀>"
acr_password="<登录密码>"
echo '{"auths":{"'${acr_registry}'":{"username":"'${acr_username}'","password":"'${acr_password}'"}}}' > ~/.docker/acr-auth.jsonkcr_registry="xxx.ksyunkcr.com"
kcr_username="<用户名>"
kcr_password="<访问凭据>"
echo '{"auths":{"'${kcr_registry}'":{"username":"'${kcr_username}'","password":"'${kcr_password}'"}}}' > ~/.docker/kcr-auth.json检查阿里云镜像
skopeo inspect docker://xxxx.cn-beijing.personal.cr.aliyuncs.com/skopeo-test/nginx-test:latest将阿里云镜像迁移到金山云
skopeo copy \
--src-authfile ~/.docker/acr-auth.json \
--dest-authfile ~/.docker/kcr-auth.json \
docker://xxxx.cn-beijing.personal.cr.aliyuncs.com/skopeo-test/nginx-test:latest \
docker://xxx.ksyunkcr.com/skopeo-test/nginx-test:latest#!/bin/bash
IMAGES=(
"nginx-test:latest"
"redis-test:latest"
)
for img in "${IMAGES[@]}"; do
skopeo copy \
--src-authfile ~/.docker/acr-auth.json \
--dest-authfile ~/.docker/kcr-auth.json \
"docker://xxxx.cn-beijing.personal.cr.aliyuncs.com/skopeo-test/$img" \
"docker://xxx.ksyunkcr.com/skopeo-test/$img"
done进入 镜像仓库 → 命名空间 → 仓库名,确认镜像已同步成功。
skopeo inspect --authfile ~/.docker/kcr-auth.json docker://xxxx.ksyunkcr.com/skopeo-test/nginx-test:latest纯净模式
