3.5. 将容器镜像上传到镜像 registry
要在 air-gapped 站点中使用容器镜像,请按照以下步骤将其上传到镜像 registry。
先决条件
-
通过访问
microshift-quay登录主机。 -
.pull-secret-mirror.json文件在本地可用。 -
microshift-containers目录内容在本地可用。
流程
运行以下命令,安装用于复制容器镜像的
skopeo工具:$ sudo dnf install -y skopeo设置指向 pull secret 文件的环境变量:
$ IMAGE_PULL_FILE=~/.pull-secret-mirror.json设置指向本地容器镜像目录的环境变量:
$ IMAGE_LOCAL_DIR=~/microshift-containers设置指向镜像 registry URL 的环境变量,以上传容器镜像:
$ TARGET_REGISTRY=<registry_host>:<port>1 - 1
- 将
<registry_host>:<port> 替换为镜像 registry 服务器的主机名和端口。
运行以下脚本,将容器镜像上传到
${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