AdSense

網頁

2023/2/5

Docker 推送image至Docker Hub

Docker將本地建置的image推送到Docker Hub。


範例環境:

  • macOS Ventura 13.1
  • Docker 20.10.21


登入Docker Hub

在命令列輸入docker login及Docker Hub的帳密以存取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: <username>
Password: **********
Login Succeeded

Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/


tag image

把本地image推到Docker Hub repository則image的名稱格式必須為<hub-user>/<repo-name><hub-user>為Docker Hub的使用者名稱;<repo-name>為image在Docker Hub存放的repository名稱。

例如要推送的本地image原名是go-demo

% docker images
REPOSITORY        TAG         IMAGE ID       CREATED       SIZE
go-demo           latest      9fef9e714dc5   4 hours ago   363MB

要推送的Docker Hub帳號為matthung0807,則在命令列輸入docker tag go-demo matthung0807/go-demo:latestgo-demo image tag為另一個新的matthung0807/go-demo image,後面的:latest為repository上的版號。

% docker tag go-demo matthung0807/go-demo:latest

輸入docker images可看到新增的matthung0807/go-demo image。

% docker images
REPOSITORY             TAG         IMAGE ID       CREATED       SIZE
go-demo                latest      9fef9e714dc5   4 hours ago   363MB
matthung0807/go-demo   latest      9fef9e714dc5   4 hours ago   363MB


push image

命令列輸入docker push matthung0807/go-demo:latest推送matthung0807/go-demo:latest image。

% docker push matthung0807/go-demo:latest
The push refers to repository [docker.io/matthung0807/go-demo]
1bdb3657b74a: Pushed
e96b6e34fccb: Pushed
f46d337b0c2e: Pushed
1cee9efb8630: Pushed
5739252b30ab: Mounted from library/golang
4329a19fb408: Mounted from library/golang
c1bfd5512d71: Mounted from library/golang
8e012198eea1: Mounted from library/golang
latest: digest: sha256:40b59b420c5b91453811319477197eeeb495c50de9311085107d5587d201ae54 size: 1992

Push完成後即可在Docker Hub的repository找到推送來的image matthung0807/go-demo




沒有留言:

AdSense