使用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
镜像的时候,也就不需要登录了。