1. 程式人生 > >docker推送自己的映象到docker hub

docker推送自己的映象到docker hub

環境:

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

歡迎補充指正!