iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 6
0
DevOps

Docker獸 究極進化 ~~ Kubernetes獸系列 第 6

Day-6 乘載 Docker Image的靈魂 Docker Hub & Github Packages

前言

這章節教大家把製作完成的docker image給push上自己的registry,我們會以docker hub 以及github為例,因為這兩個registry相對難度較低,且有提供免費方案給使用者進行side project開發與練習。

Docker hub:

Regist docker hub account

go to https://hub.docker.com/

Sign up a docker Id with the email of your github.

https://ithelp.ithome.com.tw/upload/images/20200921/201297372qJ7CNFzOh.png

Sign in your docker hub

登入後請點選 Create Repository,並創建一個docker repository(建議選用前面練習時所創建的image名稱。)

https://ithelp.ithome.com.tw/upload/images/20200921/20129737cjfALCqVBY.png

Push your image to hub

docker push /:

創建好hub後,請將先前練習的docker image改名為上面push command的形式

$ docker tag ironman:latest ghjjhg567/ironman:latest

在本機登入你的hub account,並push image至你的hub上

$ docker login
$ docker push ghjjhg567/ironman:latest
The push refers to repository [docker.io/ghjjhg567/ironman]
34877f5982a5: Layer already exists
4baa862b43b4: Layer already exists
077e55bf1234: Layer already exists
f6ff27009601: Pushed
c64e397c459d: Layer already exists
5dcc42e3e97b: Layer already exists
28ba7458d04b: Layer already exists
838a37a24627: Layer already exists
a6ebef4a95c3: Layer already exists
b7f7d2967507: Layer already exists
latest: digest: sha256:867ebc8311eccd77994a7301cd4af55d3f36eed9e25f5a30f7ce0c5719faece6 size: 2410

之後到hub上確認是否有將image成功push上去。

Sync with your github

點選Repository/Builds

https://ithelp.ithome.com.tw/upload/images/20200921/20129737quAlNpxrX8.png

之後請選擇該專案的repository,並在下方BUILD RULES進行調整。

  • 請選擇想auto build的branch以及build後的tag
  • 再來選擇該專案中Dockerfile的檔案位置,與路徑。
  • 之後請Save

https://ithelp.ithome.com.tw/upload/images/20200921/20129737m5Q4efXcL2.png

Notifications

當你想要在你build新image時,收到通知的話,請至Account settings/Notifications進行設定。

目前hub提供寄信以及sync SLACK功能給使用者使用。

https://ithelp.ithome.com.tw/upload/images/20200921/20129737KHjTntKv4k.png

Test hub auto build

最後就能push一個新的commit至上面所設定的branch,看docker hub的auto build有沒有執行以及Notifications有沒有寄信。

GIthub Registry

這邊先假設大家都有自己的github帳號了,沒有的人在自行去創建。

Login your github registry

docker login docker.pkg.github.com -u -p

docker login docker.pkg.github.com -u -p

這邊比較建議使用token,原因是建立token時能夠自行設定權限,即使被盜取token,駭客能做的事也比較有限。

Create your token

  • 點選右上方settings
  • 點選developer settings

https://ithelp.ithome.com.tw/upload/images/20200921/20129737RKcjrjjCQu.png

  • 選擇 Personal access tokens

https://ithelp.ithome.com.tw/upload/images/20200921/20129737WQf6qb61Gn.png

  • 輸入token名稱以及點選授權之權限(建議只給read, write packages就好)

https://ithelp.ithome.com.tw/upload/images/20200921/20129737xzNdZKKHKG.png

Rename your image

docker tag docker.pkg.github.com///:

$ docker tag ghjjhg567/ironman:latest docker.pkg.github.com/neskem/ironman_2020/ironman:latest

注意一下,這邊與docker hub較為不同地方在於,github registry需要加上repoistory的名稱!

Push your image

docker push docker.pkg.github.com///:

$ docker push docker.pkg.github.com/neskem/ironman_2020/ironman:latest
The push refers to repository [docker.pkg.github.com/neskem/ironman_2020/ironman]
34877f5982a5: Pushed
4baa862b43b4: Pushed
077e55bf1234: Pushed
f6ff27009601: Pushed
c64e397c459d: Pushed
5dcc42e3e97b: Pushed
28ba7458d04b: Pushed
838a37a24627: Pushed
a6ebef4a95c3: Pushed
b7f7d2967507: Pushed
latest: digest: sha256:babe811cf46948c3c9fee1030fb7eb81b999222eb5a8fe5dbb4eb38abea378fa size: 2410

Download your image

docker pull docker.pkg.github.com///:

Push成功後,你能到你的github repository的右下角看到一個packages的小鯨魚

https://ithelp.ithome.com.tw/upload/images/20200921/20129737dGoH4g0P9M.png

點進去後能看到該repository下所有的images

https://ithelp.ithome.com.tw/upload/images/20200921/20129737ej8TV6Cqkn.png

點選指定image也會提供你相關資訊

https://ithelp.ithome.com.tw/upload/images/20200921/20129737XSgqiDqqlY.png

小結

這次介紹給大家兩個常見而且免費(有資源限制)的registry給大家認識,讓大家能夠透過這兩個registry來練習或是存放自己的image!

https://ithelp.ithome.com.tw/upload/images/20200921/20129737Zp6LdqRJLP.png

Reference

https://hub.docker.com

https://docs.github.com/en/actions/guides/publishing-docker-images


上一篇
Day-5 煉成 Docker Image
下一篇
Day-7 解析 Docker Volume
系列文
Docker獸 究極進化 ~~ Kubernetes獸30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言