Search code examples
dockerdocker-desktop

How to get value from docker-credential-osxkeychain


How do you get credentials

Docker describe it as getting it from config.json but it is in "credsStore" and how do you get it out from there?

 cat ~/.docker/config.json
{
    "auths": {
        "https://index.docker.io/v1/": {}
    },
    "credsStore": "desktop",
    "experimental": "enabled",
    "stackOrchestrator": "swarm"
}

Using docker-credential-osxkeychain get <??>

It is like no matter what I try to "get" is comes back with:

docker-credential-osxkeychain <store|get|erase|list|version>

Solution

  • Short answer

    the command docker-credentials-osxkeychain get reads from standard input and expects server url as described here so one can do something like

    $ echo "https://index.docker.io/v1/" | docker-credential-osxkeychain get
    

    You can find the server url using docker-credential-osxkeychain list

    $ docker-credential-osxkeychain list
    {"https://index.docker.io/v1/":"someuser"}
    

    Long answer

    First, you might want to change credsStore to osxkeychain which makes ~/.docker/config.json look like

    {
      "stackOrchestrator" : "swarm",
      "credsStore" : "osxkeychain",
      "auths" : {
    
      },
      "experimental" : "disabled"
    }
    

    Second, login with docker cli using docker login

    $ docker login
    Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
    Username: someuser
    Password:
    Login Succeeded
    

    On successful login, docker-credential-osxkeychain has stored the username and password in osxkeychain which can be retrieved using docker-credential-osxkeychain get

    $ docker-credential-osxkeychain list
    {"https://index.docker.io/v1/":"someuser"}
    

    we can use the url as the key to get our credentials note: docker-credential-osxkeychain get uses stdin to read the input.

    $ echo "https://index.docker.io/v1/" | docker-credential-osxkeychain get
    {"ServerURL":"https://index.docker.io/v1/","Username":"someuser","Secret":"your-actual-password"}