denied: requested access to the resource is denied

使用docker push镜像时,出现denied: requested access to the resource is denied
原因和Git push代码一样,为了安全起见,在Docker Hub无法确定操作者的情况下,是无法完成push操作的。在Git中是通过配置文件SSH Keys来记住用户,那么在Docker Hub中也是通过配置文件。
通常在你第一次使用docker login命令登录你的Docker仓库时,会自动在你的机器上生成一个config.json的文件,目录具体位置不定。如果你是root用户操作,一般在/root/.docker/config.json目录。如果是普通用户,那么可能在~/.docker/config.json目录上。

[benben@localhost testpush]$ 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: benben_2015
Password: 
WARNING! Your password will be stored unencrypted in /home/benben/.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 login登录即可。如果上面的目录中有config.json文件,则会更新,如果没有,则会生成一个新的。接着再使用docker push镜像就行。下次push镜像的时候,也就不需要登录了。


版权声明:本文为benben_2015原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。