Symbols count in article:
1.2k
Reading time:
5 mins.
Container Registry:Image Storage and Distribution
Docker Hub:探尋的更深入
Container Registries
- 你的 Container plan 需要有 Image Registry 成為 plan 的一部分
- 更多 Docker Hub 的細節,包含 auto-build
- Docker Store 是怎麼樣跟 Hub 不一樣
- Docker Cloud 是怎麼樣跟 Hub 不一樣
- 使用 Cloud 的新 Swarm 功能來讓 Mac/Win 跟 Swarm 連線
- 安裝和使用 Docker Registry,且當作 private image store
- 第三方 registry 套件選項
Docker Hub:探尋的更深入
- 最有名的 public image registry
- 它是真的 Docker Registry 而且最輕量的 image building
- 讓我們探索更多 Docker Hub 的功能
- 連結 GitHub/BitBucket 到 Hub 而且自動建立 images commit
- 將 image building 串連在一起
Docker Store:它可以做什麼?
- 下載 Docker “Editions”
- 找到認證過的 Docker/Swarm 外掛和商業認證的 images
Docker Cloud:CI/CD 和 Server Ops
- Web based Docker Swarm 創建/管理
- 使用有名的雲端主機商和自建式伺服器
- 自動化的 image building、測試和部署
- 跟 Docker Hub 免費的東西相比更進階
- 包含 image 安全掃描服務
使用 Docker Cloud 來做簡單的遠端 Swarm 管理
- 觀看此影片
了解 Docker Registry
- 一個提供給你的網路的私有 image registry
- Docker/Distribution Github Repo 的一部分
- 事實上在私有的 container registry
- 不像完整功能的 Hub 或其它東西,它沒有完整的網頁介面,只有基本的認證
- 在核心的部分:一個網頁的 API 和儲存系統,用 Go 語言撰寫
- 儲存系統支援 local、S3/Azure/Alibaba/Google 雲,還有 OpenStack Swift
- 查看以下資源:
運行一個私有的 Docker Registry
- 運行 registry image 在預設 port 5000
- Re-tag 已存在的 image,且推送它到你的新 registry
- 從本地端 cache 移除 image,且從新的 registry pull 下來
- 使用 bind mount 來 Re-create registry,且觀察它如何儲存資料
Registry 和適合的 TLS
- 「預設加密」:Docker 不會用沒有 HTTPS 的方式跟 registry 溝通,除了 localhost (127.0.0.0/8)
- 對於遠端自行登入的 TLS,要再引擎啟動 「insecure-registry」
- 運行私有 registry image
docker container run -d -p 5000:5000 --name registry registry
docker pull hello-world
下載很輕量的 image 來測試
- Re-tag 已存在的 image,且推送它到你的新 registry
docker tag hello-world 127.0.0.1:5000/hello-world
docker push 127.0.0.1:5000/hello-world
- 從本地端 cache 移除 image,且從新的 registry pull 下來
docker image remove hello-world
docker image remove 127.0.0.1:5000/hello-world
docker pull 127.0.0.1:5000/hello-world
docker container kill registry
docker container rm registry
- 使用 bind mount 來 Re-create registry,且觀察它如何儲存資料
docker container run -d -p 5000:5000 --name registry -v $(pwd)/registry-data:/var/lib/registry registry
docker push 127.0.0.1:5000/hello-world
tree registry-data
安裝 Docker 自動完成
- Oh-my-zsh
- docker-zsh-completion
作業:使用 TLS 和認證加密 Docker Registry
- 透過創建給 HTTPS 的 self-signed 認證和啟動 htpasswd 認證可以學習到基礎
- 會使用 Play With Docker 來完成這個作業
- 建議使用 Part 2 and 3 of "Docker Registry for Linux 來完成作業,或是跳回 Part 1 且在他們的 infrastructure 上運行 container,使用他們的實際 Docker Engine 的 web-based 介面學習 PWD 怎麼運作的
- 更多實驗請參考:點此
跟 Swarm 一起使用 Registry
- 跟 localhost 用一樣的方式
- 由於 Routing Mesh,所有的節點可以在 127.0.0.1:5000 被看到
- 記得決定如何儲存 image (volume driver)
- 筆記:所有的 nodes 都要可以存取 images
- 專業的技巧:如果可以的話,使用 hosted SaaS registry
docker service create --name registry --publish 5000:5000 registry
- 在 5000 port 的 console 後面加上 v2/_catalog 可以看到 json 格式的紀錄
docker pull hello-world
docker tag hello-world 127.0.0.1:5000/hello-world
docker push 127.0.0.1:5000/hello-world
- 在 5000 port 的 console 後面加上 v2/_catalog 可以看到
{"repositories":["hello-world"]}
docker pull nginx
docker tag nginx 127.0.0.1:5000/nginx
docker push 127.0.0.1:5000/nginx
docker service create --name nginx -p 80:80 --replicas 5 --detach=false 127.0.0.1:5000/nginx
docker service ps nginx
就可以看到它使用的是本機端的 image (127.0.0.1:5000/nginx:latest)
Docker 的第三方套件
- 最流行的是:Quay.io
- 如果使用 AWS、Azure、Google Cloud,他們都有自己專屬的 registry
- 如果是自建式主機,Docker EE、Quay Enterprise、GitLab
- 更多詳細的 registry 清單
額外的課程
- Journey to Docker Production: Evolving Your Infrastructure and Processes
- What host OS should I use?
- What base FROM images should I use?
- How should my Swarm node design look?
- What common issues do people have when starting a production docker project?
- How to limit the project from trying to change too much at once.
- How to speed up the project by outsourcing small pieces of solution to existing products.
- How Docker’s Enterprise/Cloud products can help.
- Everything You Thought You Already Knew About Orchestration
- Docker tip: docker system prune and df
- Docker 17.06 Community Edition
完成課程