【发布时间】:2019-03-15 04:52:20
【问题描述】:
我正在使用Docker SDK for Python 将本地图像存储库推送到 Docker Registry(在我的例子中是 DockerHub。)
我在文档here 中描述的“client.images”上使用“push”方法。
很遗憾,所有已发布的存储库都是公开的。似乎没有标志可以推送到私有存储库或确保推送的存储库是私有的。这可以通过 Docker Python API 实现吗?
我以三种不同的方式进行了尝试(所有方法都只生成公共回购):
- 方法一:单独登录 (有效,但导致公共回购):
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)
- 方法二:凭证传递给推送调用 (有效,但导致公共回购):
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)
- 方法三:命令行登录(不通过代码) (有效,但导致公共回购):
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 帐户后,显然身份验证工作。但是,图像始终是公开的。
【问题讨论】:
-
可以分享python代码吗?
-
@ozlevka 谢谢。现在包括代码。
标签: docker sdk docker-api