pythondockerdocker-registrydockerpy

docker-py: Login to private registry using ~/.docker/config.json auth token


I stored my credentials to access a private registry in the ~/.docker/config.json file. Therefore I can simply run docker login <url> without explicitely stating my credentials. Is there a way to replicate this behaviour using docker-py?

All I could find was this login method, which always requires a username. Using the cli all I need is the registry host name (and the ~/.docker/config.json file with the auth token to this registry).

Is that somehow achievable? T


Solution

  • Below is the login method and options available.

    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``)
    

    And as per that, dockercfg_path, is present for the login method where you can use that file.

    From experimenting, Though, that this username is ignored for the credentials saved in .docker/config.json, so I just use a random value and it is working.