我将我的凭据存储在~/.docker/config.json
文件中以访问私有注册表。因此,我可以简单地运行docker login <url>
而无需明确说明我的凭据。有没有办法使用docker-py复制此行为?
我能找到的只是这个login方法,它总是需要一个用户名。使用cli,我需要的只是注册表主机名(以及带有该注册表的auth令牌的~/.docker/config.json
文件)。
这可以实现吗? T
答案 0 :(得分:1)
下面是login
方法和可用选项。
login()
Authenticate with a registry. Similar to the docker login command.
Parameters:
username (str) – The registry username
password (str) – The plaintext password
email (str) – The email for the registry account
registry (str) – URL to the registry. E.g. https://index.docker.io/v1/
reauth (bool) – Whether or not to refresh existing authentication on the Docker server.
dockercfg_path (str) – Use a custom path for the Docker config file (default $HOME/.docker/config.json if present, otherwise``$HOME/.dockercfg``)
此外,登录方法中还提供了 dockercfg_path 。
尽管经过实验,但是保存在.docker / config.json中的凭据忽略了此username
,所以我只是使用一个随机值,它就可以了。