github.com/sld880311/docker@v0.0.0-20200524143708-d5593973a475/docs/reference/commandline/login.md (about)

     1  ---
     2  title: "login"
     3  description: "The login command description and usage"
     4  keywords: "registry, login, image"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/docker Github
     8       repository at https://github.com/docker/docker/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # login
    17  
    18  ```markdown
    19  Usage:  docker login [OPTIONS] [SERVER]
    20  
    21  Log in to a Docker registry.
    22  If no server is specified, the default is defined by the daemon.
    23  
    24  Options:
    25        --help              Print usage
    26    -p, --password string   Password
    27    -u, --username string   Username
    28  ```
    29  
    30  ## Description
    31  
    32  Login to a registry.
    33  
    34  ### Login to a self-hosted registry
    35  
    36  If you want to login to a self-hosted registry you can specify this by
    37  adding the server name.
    38  
    39  ```bash
    40  $ docker login localhost:8080
    41  ```
    42  
    43  ### Privileged user requirement
    44  
    45  `docker login` requires user to use `sudo` or be `root`, except when:
    46  
    47  1.  connecting to a remote daemon, such as a `docker-machine` provisioned `docker engine`.
    48  2.  user is added to the `docker` group.  This will impact the security of your system; the `docker` group is `root` equivalent.  See [Docker Daemon Attack Surface](https://docs.docker.com/security/security/#docker-daemon-attack-surface) for details.
    49  
    50  You can log into any public or private repository for which you have
    51  credentials.  When you log in, the command stores encoded credentials in
    52  `$HOME/.docker/config.json` on Linux or `%USERPROFILE%/.docker/config.json` on Windows.
    53  
    54  ### Credentials store
    55  
    56  The Docker Engine can keep user credentials in an external credentials store,
    57  such as the native keychain of the operating system. Using an external store
    58  is more secure than storing credentials in the Docker configuration file.
    59  
    60  To use a credentials store, you need an external helper program to interact
    61  with a specific keychain or external store. Docker requires the helper
    62  program to be in the client's host `$PATH`.
    63  
    64  This is the list of currently available credentials helpers and where
    65  you can download them from:
    66  
    67  - D-Bus Secret Service: https://github.com/docker/docker-credential-helpers/releases
    68  - Apple macOS keychain: https://github.com/docker/docker-credential-helpers/releases
    69  - Microsoft Windows Credential Manager: https://github.com/docker/docker-credential-helpers/releases
    70  
    71  You need to specify the credentials store in `$HOME/.docker/config.json`
    72  to tell the docker engine to use it:
    73  
    74  ```json
    75  {
    76  	"credsStore": "osxkeychain"
    77  }
    78  ```
    79  
    80  If you are currently logged in, run `docker logout` to remove
    81  the credentials from the file and run `docker login` again.
    82  
    83  ### Credential helper protocol
    84  
    85  Credential helpers can be any program or script that follows a very simple protocol.
    86  This protocol is heavily inspired by Git, but it differs in the information shared.
    87  
    88  The helpers always use the first argument in the command to identify the action.
    89  There are only three possible values for that argument: `store`, `get`, and `erase`.
    90  
    91  The `store` command takes a JSON payload from the standard input. That payload carries
    92  the server address, to identify the credential, the user name, and either a password
    93  or an identity token.
    94  
    95  ```json
    96  {
    97  	"ServerURL": "https://index.docker.io/v1",
    98  	"Username": "david",
    99  	"Secret": "passw0rd1"
   100  }
   101  ```
   102  
   103  If the secret being stored is an identity token, the Username should be set to
   104  `<token>`.
   105  
   106  The `store` command can write error messages to `STDOUT` that the docker engine
   107  will show if there was an issue.
   108  
   109  The `get` command takes a string payload from the standard input. That payload carries
   110  the server address that the docker engine needs credentials for. This is
   111  an example of that payload: `https://index.docker.io/v1`.
   112  
   113  The `get` command writes a JSON payload to `STDOUT`. Docker reads the user name
   114  and password from this payload:
   115  
   116  ```json
   117  {
   118  	"Username": "david",
   119  	"Secret": "passw0rd1"
   120  }
   121  ```
   122  
   123  The `erase` command takes a string payload from `STDIN`. That payload carries
   124  the server address that the docker engine wants to remove credentials for. This is
   125  an example of that payload: `https://index.docker.io/v1`.
   126  
   127  The `erase` command can write error messages to `STDOUT` that the docker engine
   128  will show if there was an issue.
   129  
   130  ### Credential helpers
   131  
   132  Credential helpers are similar to the credential store above, but act as the
   133  designated programs to handle credentials for *specific registries*. The default
   134  credential store (`credsStore` or the config file itself) will not be used for
   135  operations concerning credentials of the specified registries.
   136  
   137  ### Logging out
   138  
   139  If you are currently logged in, run `docker logout` to remove
   140  the credentials from the default store.
   141  
   142  Credential helpers are specified in a similar way to `credsStore`, but
   143  allow for multiple helpers to be configured at a time. Keys specify the
   144  registry domain, and values specify the suffix of the program to use
   145  (i.e. everything after `docker-credential-`).
   146  For example:
   147  
   148  ```json
   149  {
   150    "credHelpers": {
   151      "registry.example.com": "registryhelper",
   152      "awesomereg.example.org": "hip-star",
   153      "unicorn.example.io": "vcbait"
   154    }
   155  }
   156  ```