3.5. 将容器镜像上传到镜像 registry


要在 air-gapped 站点中使用容器镜像,请按照以下步骤将其上传到镜像 registry。

先决条件

  • 通过访问 microshift-quay 登录主机。
  • .pull-secret-mirror.json 文件在本地可用。
  • microshift-containers 目录内容在本地可用。

流程

  1. 运行以下命令,安装用于复制容器镜像的 skopeo 工具:

    $ sudo dnf install -y skopeo
    Copy to Clipboard Toggle word wrap
  2. 设置指向 pull secret 文件的环境变量:

    $ IMAGE_PULL_FILE=~/.pull-secret-mirror.json
    Copy to Clipboard Toggle word wrap
  3. 设置指向本地容器镜像目录的环境变量:

    $ IMAGE_LOCAL_DIR=~/microshift-containers
    Copy to Clipboard Toggle word wrap
  4. 设置指向镜像 registry URL 的环境变量,以上传容器镜像:

    $ TARGET_REGISTRY=<registry_host>:<port> 
    1
    Copy to Clipboard Toggle word wrap
    1
    <registry_host>:<port> 替换为镜像 registry 服务器的主机名和端口。
  5. 运行以下脚本,将容器镜像上传到 ${TARGET_REGISTRY} 镜像 registry:

    image_tag=mirror-$(date +%y%m%d%H%M%S)
    image_cnt=1
       # Uses timestamp and counter as a tag on the target images to avoid
       # their overwrite by the 'latest' automatic tagging
    
    pushd "${IMAGE_LOCAL_DIR}" >/dev/null
    while read -r src_manifest ; do
       # Remove the manifest.json file name
       src_img=$(dirname "${src_manifest}")
       # Add the target registry prefix and remove SHA
       dst_img="${TARGET_REGISTRY}/${src_img}"
       dst_img=$(echo "${dst_img}" | awk -F'@' '{print $1}')
    
       # Run the image upload command
       echo "Uploading '${src_img}' to '${dst_img}'"
       skopeo copy --all --quiet \
          --preserve-digests \
          --authfile "${IMAGE_PULL_FILE}" \
          dir://"${IMAGE_LOCAL_DIR}/${src_img}" docker://"${dst_img}:${image_tag}-${image_cnt}"
       # Increment the counter
       (( image_cnt += 1 ))
    
    done < <(find . -type f -name manifest.json -printf '%P\n')
    popd >/dev/null
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat