在发布镜像的时候,经常要先执行 docker login -u xxx -p xxx 操作,但是在通过脚本发布项目的时候,就会有问题,因为不能直接交互,
所以 可以在执行脚本的机器上先执行 docker login -u xxx -p xxx 这个是docker 仓库默认登录操作,如果是推送到自己的仓库,那么需
要执行如下命令,下面这个我推到了阿里云的镜像仓库:
[root@k8smaster .docker]# docker login --username=xxx registry.cn-qingdao.aliyuncs.com
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
执行按以后就可以执行推送命令了:
[root@k8smaster ~]# docker push registry.cn-qingdao.aliyuncs.com/xxx/httpd:v1.0.2
以后可以直接 docker push 到指定仓库,不需要再登录,原因是在 /root/.docker/config.json (~/.docker/config.json) 这个文件里面保存了仓库的授权信息
格式如下:
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "faddsdsgdfgfddfssfdg"
},
"registry.cn-qingdao.aliyuncs.com": {
"auth": "zxvcfdsfegvbfbsdfsdsddsfd"
}
}
}
同时config.json里的授权文件可以复制到其它服务器上,仍然有效,可以直接使用,这个在做k8s的项目自动打包发布的时候特别有用,在后面的项目里面我会用到这个
