繁体   English   中英

通过 Docker API 将私有镜像推送到 Docker Registry

[英]Push Private Image to Docker Registry via Docker API

我正在使用Docker SDK for Python将本地图像存储库推送到 Docker Registry(在我的例子中是 DockerHub。)

我在文档here中描述的“client.images”上使用“push”方法。

不幸的是,所有已发布的存储库都是公开的。 似乎没有标志可以推送到私有存储库或确保推送的存储库是私有的。 这可以通过 Docker Python API 实现吗?

我以三种不同的方式尝试了这个(所有结果都只导致公共回购):

  1. 方法一:单独登录(有效,但导致公共回购):
 client = docker.from_env() auth_client = client.login(username = "kelly_peyton", password = "nightingale", email = "kpeyton@prophet5.org", registry = "docker.io", reauth = True) # other code here, not shown, to validate login succeeded cli = APIClient(base_url="unix:///var/run/docker.sock") br = cli.build(path = temp_local, dockerfile = f"{temp_local}/Dockerfile", tag = docker_repo_reference_tagged) # other code here, not shown, to validate build succeeded push_res = cli.push(repository = f"{docker_repo_reference}", tag = docker_repo_tag, stream = False, decode = False)
  1. 方法二:传递给推送调用的凭据(有效,但导致公共回购):
 client = docker.from_env() cli = APIClient(base_url="unix:///var/run/docker.sock") br = cli.build(path = temp_local, dockerfile = f"{temp_local}/Dockerfile", tag = docker_repo_reference_tagged) # other code here, not shown, to validate build succeeded push_res = cli.push(repository = f"{docker_repo_reference}", tag = docker_repo_tag, stream = False, auth_config = { "username" : "kelly_peyton", "password" : "nightingale", "email" : "kpeyton@prophet5.org", "registry" : "docker.io" }, decode = False)
  1. 方法三:命令行登录(不是通过代码)(有效,但会导致公共回购):
 client = docker.from_env() cli = APIClient(base_url="unix:///var/run/docker.sock") br = cli.build(path = temp_local, dockerfile = f"{temp_local}/Dockerfile", tag = docker_repo_reference_tagged) # other code here, not shown, to validate build succeeded push_res = cli.push(repository = f"{docker_repo_reference}", tag = docker_repo_tag, stream = False, decode = False)

所有三种方法都有效,因为图像确实被推送到注册表(在我的例子中是 DockerHub),并且自从我推送到我的私人 DockerHub 帐户后,身份验证显然有效。 但是,图像始终是公开的。

您不能通过将凭据设置为 API 来使 repo 私有。 它使您只能将图像推送到您的存储库。

您应该创建或将 repo 转换为私有。 请阅读文档以了解如何操作。 通常,只有您可以推送到 repo。 如果 repo public 那么每个人都可以下载,如果 repo private 那么只有你可以下载。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM