搭建私有docker倉庫並使用OSS作為隱藏

來源:互聯網
上載者:User

摘要: 本文主要是示範如果快速搭建一個私有的docker倉庫,並且使用OSS作為隱藏,docker的用法以及docker倉庫的其他設定,不在本文討論範圍

本文主要是示範如果快速搭建一個私有的docker倉庫,並且使用OSS作為隱藏,docker的用法以及docker倉庫的其他設定,不在本文討論範圍

安裝docker-engine

以centos 7 為例

yum update

tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

yum install docker-engine

systemctl enable docker.service
systemctl start docker
systemctl docker status

編輯設定檔

  • endpoint:存取oss的連結,主要分為公網、經典網路內網和VPC下內網,構成方式為bucket+各個endpointOSS region和endpoint詳細清單
  • region:Region英文表示
  • bucket:OSS的bucket名稱

假設OSS是在美西,bucket是t-docker-registry,通過經典網路內網存取OSS,下面是一個基礎版的完整設定
設定檔詳細說明

version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
oss:
accesskeyid: ${accesskeyid}
accesskeysecret: ${accesskeysecret}
secure: false
region: oss-us-west-1
endpoint: t-docker-registry.oss-us-west-1-internal.aliyuncs.com
bucket: t-docker-registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3

啟動任務

設定檔路徑/root/docker-registry/config-registry.yml

啟動docker倉庫

docker run -d -p 5000:5000 --restart=always --name registry -v /root/docker-registry/config-registry.yml:/etc/docker/registry/config.yml registry:2

測試本地倉庫

追蹤一個dockerimage

docker pull hello-world

修改tag

docker tag hello-world 127.0.0.1:5000/hello-world

發送鏡像到本地倉庫

docker push 127.0.0.1:5000/hello-world

發送成功後返回類似如下資訊

[root@host docker-registry]# docker push 127.0.0.1:5000/hello-world
The push refers to a repository [127.0.0.1:5000/hello-world]
a02596fdd012: Mounted from hello-world
latest: digest: sha256:a18ed77532f6d6781500db650194e0f9396ba5f05f8b50d4046b294ae5f83aa4 size: 524
[root@host docker-registry]#

同時在OSS主控台對應的bucket下面可以看到建立了相應的檔案

測試拉去image,先移除本地的image

docker rmi 127.0.0.1:5000/hello-world

查看本地image倉庫,裡面已經沒有了127.0.0.1:5000/hello-world

docker images

從本地docker倉庫拉去127.0.0.1:5000/hello-world

docker pull 127.0.0.1:5000/hello-world

成功後返回類似如下資訊

[root@host docker-registry]# docker pull 127.0.0.1:5000/hello-world
Using default tag: latest
latest: Pulling from hello-world
Digest: sha256:a18ed77532f6d6781500db650194e0f9396ba5f05f8b50d4046b294ae5f83aa4
Status: Downloaded newer image for 127.0.0.1:5000/hello-world:latest

查看本地image倉庫,裡面已經有了127.0.0.1:5000/hello-world

docker images

相關產品:

  1. 物件隱藏OSS
  2. 容器服務(Docker)
  3. 區塊存放裝置
  4. 雲端服務器ECS
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.