转载: https://www.jianshu.com/p/60bce40a1681
Docker login命令用于登陆Docker Registry。
用法
[root@localhost .docker]# docker login --help
Usage: docker login [OPTIONS] [SERVER]
Log in to a Docker registry
Options:
-p, --password string Password
--password-stdin Take the password from stdin
-u, --username string Username
登录官方仓库
命令默认登录就是官方仓库
[root@localhost .docker]# docker login --username=wallezz
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
登录私有仓库
需要指定仓库的主机名,而且需要支持https连接,不然就需要hack一下。
[root@localhost .docker]# docker login --username=admin harbor.docker-plus.xyz
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
查看登录状态
Docker会将token存储在~/.docker/config.json文件中,从而作为拉取私有镜像的凭证。当退出服务器时会自动删除token。
[root@localhost .docker]# cat ~/.docker/config.json
{
"auths": {
"harbor.docker-plus.xyz": {
"auth": "YWRtaW46SGFyYm9yMTIzNDU="
},
"https://index.docker.io/v1/": {
"auth": "d2FsbGV6ejoxNTgxMTA1MzExNQ=="
}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/18.09.6 (linux)"
}
}
退出官方仓库
[root@localhost .docker]# docker logout
Removing login credentials for https://index.docker.io/v1/
[root@localhost .docker]# cat ~/.docker/config.json
{
"auths": {
"harbor.docker-plus.xyz": {
"auth": "YWRtaW46SGFyYm9yMTIzNDU="
}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/18.09.6 (linux)"
}
}
退出私有仓库
[root@localhost .docker]# docker logout harbor.docker-plus.xyz
Removing login credentials for harbor.docker-plus.xyz
[root@localhost .docker]# cat ~/.docker/config.json
{
"auths": {},
"HttpHeaders": {
"User-Agent": "Docker-Client/18.09.6 (linux)"
}
}