我正在使用Docker SDK for Python将本地映像存储库推送到Docker注册表(在我的情况下为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帐户以来,显然auth起作用了。但是,这些图像始终是公开的。
答案 0 :(得分:1)
您无法通过将凭据设置为API来使回购私有。它使您只能将图像推送到您的仓库中。
您应创建或将仓库转换为私有。请阅读documentation以了解操作方法。通常,只有您可以推送到存储库。如果是repo public,那么每个人都可以下载;如果是repo private,则只有您可以下载。