Upload container images to a mirror registry

To use your container images at an air-gapped site, upload them to the mirror registry by using the following procedure.

Prerequisites
  • You logged into a host with access to microshift-quay.

  • The .pull-secret-mirror.json file is available locally.

  • The microshift-containers directory contents are available locally.

Procedure
  1. Install the skopeo tool used for copying the container images by running the following command:

    $ sudo dnf install -y skopeo
  2. Set the environment variables pointing to the pull secret file:

    $ IMAGE_PULL_FILE=~/.pull-secret-mirror.json
  3. Set the environment variables pointing to the local container image directory:

    $ IMAGE_LOCAL_DIR=~/microshift-containers
  4. Set the environment variables pointing to the mirror registry URL for uploading the container images:

    $ TARGET_REGISTRY=<registry_host>:<port>
    • Replace <registry_host>:<port> with the hostname and port of your mirror registry server.

  5. Run the following script to upload the container images to the ${TARGET_REGISTRY} mirror registry:

    pushd "${IMAGE_LOCAL_DIR}" >/dev/null
    while read -r src_manifest ; do
      local src_img
      src_img=$(dirname "${src_manifest}")
      # Add the target registry prefix and remove SHA
      local -r dst_img="${TARGET_REGISTRY}/${src_img}"
      local -r dst_img_no_tag="${TARGET_REGISTRY}/${src_img%%[@:]*}"
      # Run the image upload
      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}"
    done < <(find . -type f -name manifest.json -printf '%P\n')
    popd >/dev/null