您可以将映像从 Docker 推送到注册表(如 Docker Hub 或 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
过程
- 使用 vSphere Docker Credential Helper 登录到 Harbor 注册表。
docker-credential-vsphere login <container-registry-IP> --user username@domain.com
注: 虽然可接受提供
--user username
进行登录,但是您应该使用 UserPrincipalName (UPN) 语法 (
--user username@domain.com
) 登录并使用
docker push
命令。
- 对要推入到 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/tkg-cluster-ns/hello-world latest bf756fb1ae65 10 months ago 13.3kB
hello-world latest bf756fb1ae65 10 months ago 13.3kB
- 要将映像推送到 Harbor 中的项目,请运行以下命令:
语法:
docker push <container-registry-IP>/<namespace-name>/<image_name>
例如:
docker push 10.179.145.77/tkg-cluster-ns/hello-world:latest
预期结果。
The push refers to repository [10.179.145.77/tkg-cluster-ns/hello-world]
9c27e219663c: Pushed
latest: digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 size: 525
- 验证现在映像在嵌入式 Harbor 注册表中是否可用。
- 登录到 Harbor 注册表。
- 单击处的项目链接。
- 选择存储库选项卡。
- 您应该会看到其中包含已推送到注册表的映像,格式为
namespace/image-name
,例如 tkg-cluster-ns/hello-world
。
- 选择此映像,您将看到
latest
标记和其他元数据。
- 导航回到存储库选项卡。
- 选择推送映像 Docker 命令下拉菜单。将提供用于标记映像和将映像推送到此存储库的命令。
示例
以下是另一个将映像推送到 Harbor 注册表的示例:
docker tag busybox:latest <container-registry-IP>/<namespace-name>/busybox:latest
docker push <container-registry-IP>/busybox/busybox:latest