I'm using the Docker SDK for Python to push a local image repository into a Docker Registry (DockerHub in my case.)
I use the "push" method on "client.images" described on documentation here.
Unfortunately all published repositories are public. There appears to be no flag to push into a private repository or to ensure the pushed repository is private. Is this possible with the Docker Python API?
I tried this in three separate ways (all result in a public repo only):
- Method One: Separate login (works, but results in public repo):
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)
- Method Two: Credentials passed to push call (works, but results in public repo):
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)
- Method Three: command line login (not via code) (works, but results in public repo):
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)
All three methods work since the image does indeed get pushed to the registry (DockerHub in my case), and clearly auth worked since I push to my private DockerHub account. However, the images are always public.