Can I make API calls directly against the docker registry using this library
sandhujasmine opened this issue · comments
Long story short
I'd like to make async api calls to dockerhub or any other docker registry. I don't have a docker daemon where I'll be running it so I'm testing by stopping the docker service.
I'm testing against dockerhub, trying to do something like the following which I'd like to make async:
ns_repo = "REPO_TO_QUERY"
username = "USERNAME"
password = "MY_PASSWORD"
url = f"https://auth.docker.io/token?service=registry.docker.io&scope=repository:{ns_repo}:pull"
user, access_token = (f"{username}", "{password}")
s = requests.Session()
s .auth = (user, access_token)
resp = s.get(url).json()
token = resp["token"]
url = f"https://registry-1.docker.io/v2/{ns_repo}/tags/list"
r = requests.Session().get(url, headers={"Authorization": f"Bearer {token}"})
I couldn't instantiate an object as follows:
import aiodocker
docker = aiodocker.Docker(url="http://registry-1.docker.io/")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-12-9850098bbb06> in <module>
----> 1 docker = aiodocker.Docker(url='https://registry-1.docker.io')
~/miniconda3/envs/coiled/lib/python3.8/site-packages/aiodocker/docker.py in __init__(self, url, connector, session, ssl_context, api_version)
123 self.docker_host = WIN_PRE + "localhost"
124 else:
--> 125 raise ValueError("Missing protocol scheme in docker_host.")
126 self.connector = connector
127 if session is None:
ValueError: Missing protocol scheme in docker_host.
-
Expected behaviour: I think this should work but I don't know for sure - can I query dockerhub's API with this library? Or does it talk to the docker engine API which means the docker daemon must be running?
-
Actual behaviour:
How to reproduce
import aiodocker
docker = aiodocker.Docker(url="https://registry-1.docker.io/")
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-12-9850098bbb06> in <module>
----> 1 docker = aiodocker.Docker(url='https://registry-1.docker.io')
~/miniconda3/envs/coiled/lib/python3.8/site-packages/aiodocker/docker.py in __init__(self Or is this a wrapper to query the docker daemon so the docker daemon must be running and the library is making api calls to the docker daemon, url, connector, session, ssl_context, api_version)
123 self.docker_host = WIN_PRE + "localhost"
124 else:
--> 125 raise ValueError("Missing protocol scheme in docker_host.")
126 self.connector = connector
127 if session is None:
ValueError: Missing protocol scheme in docker_host.
Your environment
As you've guessed, the client is meant to communicate with a Docker daemon and not a Docker image registry. The daemon itself would do any communication with a registry as needed (e.g. for an image pull).
Thank you @JustinTArthur - closing the issue.