docker推送自己的镜像到docker hub

版权声明:转载请注明出处,谢谢。 https://blog.csdn.net/butterfly5211314/article/details/83068807

环境:

CentOS Linux release 7.4.1708 (Core)
Linux内核:3.10.0-693.el7.x86_64
Docker:
Client: 18.06.1-ce
Server: 18.06.1-ce

构建自己的镜像

# 创建一个单独的目录
$ mkdir first-image
$ cd first-image

# 创建Dockerfile
$ cat Dockerfile
FROM alpine
MAINTAINER gerrylon [email protected]

CMD echo 'first image'

# 构建镜像
$ docker build -t first-image .

测试镜像

# 测试构建的镜像(输出first image)
$ docker run first-image
first image

推送到docker hub

下面说推送, 首先你要注册一个账号, 然后先登录:

$ 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: gerrylon # 输入用户名
Password:
WARNING! Your password will be stored unencrypted in /home/gl/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

执行推送:

# 其中 gerrylon 是注册的用户名
$ docker push gerrylon/first-image
The push refers to repository [docker.io/gerrylon/first-image]
An image does not exist locally with the tag: gerrylon/first-image

直接这样推送是不行的, 看错误An image does not exist locally with the tag: gerrylon/first-image,
本地没有tag是gerrylon/first-image的镜像.

那就先打一个tag, 再推送

$ docker tag first-image  gerrylon/first-image
$ docker push gerrylon/first-image
The push refers to repository [docker.io/gerrylon/first-image]
df64d3292fd6: Layer already exists
latest: digest: sha256:6c46501f4792391c6c59776238adf7db81b62362bfbbaf3531dc5f5ac526bdfd size: 528

可以看到没有报错, 表明成功了。

然后在个人docker hub 主页(https://hub.docker.com/u/${username}/)就可以看到了.

参考:
https://stackoverflow.com/questions/41984399/denied-requested-access-to-the-resource-is-denied-docker

欢迎补充指正!

猜你喜欢

转载自blog.csdn.net/butterfly5211314/article/details/83068807