可以将映像从 Docker 推送到嵌入式 Harbor 注册表 上的项目。嵌入式 Harbor 注册表 中的项目对应于 主管集群 上的 vSphere 命名空间。

前提条件

此外,获取对以下命名空间具有写入权限的用户帐户:与要将映像推送到其中的 Harbor 注册表 上的项目对应的命名空间。

最后,需要一个可推送到注册表的本地映像。以下命令将从 Docker Hub 中提取 hello-world 映像。您将需要一个帐户来提取映像。
docker run hello-world
预期结果:
Hello from Docker!
This message shows that your installation appears to be working correctly.
使用 docker images 命令验证映像。
docker images
REPOSITORY     TAG                 IMAGE ID            CREATED             SIZE
hello-world    latest              bf756fb1ae65        10 months ago       13.3kB

过程

  1. 使用 vSphere Docker Credential Helper 登录到 Harbor 注册表
    docker-credential-vsphere login <container-registry-IP> --user [email protected]
    注: 虽然可接受提供 --user username 进行登录,但是您应该使用 UserPrincipalName (UPN) 语法 ( --user [email protected]) 登录并使用 docker push 命令。
  2. 对要推入到 Harbor 注册表 中与命名空间同名的项目中的映像进行标记,您可以使用该映像:
    docker tag <image-name>[:TAG] <container-registry-IP>/<project-name>/<image-name>[:TAG]
    
    例如:
    docker tag hello-world:latest 10.179.145.77/tkgs-cluster-ns/hello-world:latest
    
    docker images
    REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
    10.179.145.77/tkgs-cluster-ns/hello-world     latest              bf756fb1ae65        10 months ago       13.3kB
    hello-world                                   latest              bf756fb1ae65        10 months ago       13.3kB
    
  3. 要将映像推送到 Harbor 中的项目,请运行以下命令:
    语法:
    docker push <container-registry-IP>/<namespace-name>/<image_name>
    例如:
    docker push 10.179.145.77/tkgs-cluster-ns/hello-world:latest
    
    预期结果。
    The push refers to repository [10.179.145.77/tkgs-cluster-ns/hello-world]
    9c27e219663c: Pushed
    latest: digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 size: 525
    
  4. 验证现在映像在嵌入式 Harbor 注册表中是否可用。
    • 登录到嵌入式 Harbor 注册表 控制台
    • 单击项目 > 项目名称处的项目链接。
    • 选择存储库选项卡。
    • 您应该会看到其中包含已推送到注册表的映像,格式为 namespace/image-name,例如 tkgs-cluster-ns/hello-world
    • 选择此映像,您将看到 latest 标记和其他元数据。
  5. 导航回到存储库选项卡。
  6. 选择推送映像 Docker 命令下拉菜单。将提供用于标记映像和将映像推送到此存储库的命令。

示例

以下是另一个将映像推送到嵌入式 Harbor 注册表的示例:
docker tag busybox:latest <container-registry-IP>/<namespace-name>/busybox:latest
docker push <container-registry-IP>/busybox/busybox:latest

下一步做什么

使用 Harbor 注册表中的映像部署 vSphere Pod。请参见使用嵌入式 Harbor 注册表 将应用程序部署到 vSphere Pod