[root@ct7 ~]# dao pull ubuntu:16.04html
Dao from DaoCloudpython
Initializing, Please wait a minutelinux
Using default tag: latestgit
latest: Pulling from daocloud/daocloud-toolsetgithub
efd26ecc9548: Pull complete
a3ed95caeb02: Pull complete
2719467b8a13: Pull complete
b77ed3a436e2: Pull complete
Digest: sha256:09de57ef521f2d8c056b95ba
Status: Downloaded newer image for daocloud.io/daocloud/daocloud-toolset:latest
Inital Success
# ----------------------------------------------------------------------------
# DaoCloud ToolBox for Docker
#
# DaoCloud, Inc. (c) 2016
#
# Fastest way to pull image from Docker Hub
# ----------------------------------------------------------------------------
Pulling repository library/ubuntu:16.04
ac6ad7efd0f9: Download complete
[root@ct7 ~]# docker images
REPOSITORY
ubuntu
daocloud.io/daocloud/daocloud-toolset
B.加速1.0(推薦)
加速1.0更容易明白加速原理,也更原生些。其實是啓動docker daemon時經過--registry-mirror優先指定Registry,能夠指定多條
sed -i 's#fd://#fd:// --registry-mirror http://1257c036.m.daocloud.io#' /lib/systemd/system/docker.service
systemctl daemon-reload
systemctl restart docker
[root@ct7 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
6月 09 02:10:00 ct7.example.com docker[14191]: time="2016-06-09T02:10:00.987206124+08:00" lev...nd"
6月 09 02:10:00 ct7.example.com docker[14191]: time="2016-06-09T02:10:00.987503747+08:00" lev...t."
6月 09 02:10:00 ct7.example.com docker[14191]: time="2016-06-09T02:10:00.987564135+08:00" lev...e."
6月 09 02:10:00 ct7.example.com docker[14191]: time="2016-06-09T02:10:00.987573388+08:00" lev...on"
6月 09 02:10:00 ct7.example.com docker[14191]: time="2016-06-09T02:10:00.987583790+08:00" lev...1.2
6月 09 02:10:00 ct7.example.com docker[14191]: time="2016-06-09T02:10:00.992688671+08:00" lev...ck"
6月 09 02:10:00 ct7.example.com systemd[1]: Started Docker Application Container Engine.
6月 09 02:10:25 ct7.example.com docker[14191]: time="2016-06-09T02:10:25.881743515+08:00" lev...wn"
6月 09 02:10:43 ct7.example.com docker[14191]: time="2016-06-09T02:10:43.704859767+08:00" lev...ed"
6月 09 02:10:46 ct7.example.com docker[14191]: time="2016-06-09T02:10:46.772210349+08:00" lev...nd"
Hint: Some lines were ellipsized, use -l to show in full.
搭建私有Registry2.x
1.運行registry容器(run)
docker run -d -p 5000:5000 --restart=always --name registry -v /var/lib/docker/registry:/var/lib/registry registry:2
說明:前提docker版本要1.6或更新,運行後會自動下載並啓動一個registry容器。默認會將倉庫建立在容器的/tmp/registry目錄下,-v 參數能夠指定鏡像文件存放的本地的路徑
[root@ct7 ~]# docker version
Client:
Server:
[root@ct7 ~]# docker run -d -p 5000:5000 --restart=always --name registry -v /var/lib/docker/registry:/var/lib/registry registry:2
Unable to find image 'registry:2' locally
2: Pulling from library/registry
51f5c6a04d83: Pull complete
a3ed95caeb02: Pull complete
c8064261a06d: Pull complete
619635144a24: Pull complete
c0275d66d860: Pull complete
Digest: sha256:33ea1d7ad2af5ac5d984fe34
Status: Downloaded newer image for registry:2
f099ef927cbf4e56b6479647
[root@ct7 ~]# docker ps
CONTAINER ID
f099ef927cbf
[root@ct7 ~]# netstat -tunlp|grep docker
tcp6
圖形界面
2.獲取image(pull)
docker pull ubuntu:16.04
[root@ct7 ~]# docker pull ubuntu:16.04
16.04: Pulling from library/ubuntu
5ba4f30e5bea: Pull complete
9d7d19c9dc56: Pull complete
ac6ad7efd0f9: Pull complete
e7491a747824: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:f5edf3b741a08b573eca6bf2
Status: Downloaded newer image for ubuntu:16.04
3.將獲取到的image tag到私有registry(tag)
docker tag ubuntu:16.04 localhost:5000/ubuntu:16.04
4.將獲取到的image push到私有registry(push)
docker push localhost:5000/ubuntu:16.04
[root@ct7 ~]# docker push localhost:5000/ubuntu:16.04
The push refers to a repository [localhost:5000/ubuntu]
5f70bf18a086: Pushed
737f40e80b7f: Pushed
82b57dbc5385: Pushed
19429b698a22: Pushed
9436069b92a3: Pushed
16.04: digest: sha256:4cd13bd37c4cc65e03cec370
5.stop/rm registry容器
中止registry容器
docker stop registry
刪除registry容器
docker rm -fv registry
6.指定docker私有鏡像
https://docs.docker.com/engine/reference/commandline/daemon/#insecure-registries
sed -i 's#fd://#fd://
systemctl daemon-reload
systemctl restart docker
注意:若是私有registry沒有TLS加密,則客戶端在啓動docker時要加上--insecure-registry參數,不然pull,push等都會失敗
[root@ct7 ~]# docker pull 192.168.8.254:5000/ubuntu:14.04
Error response from daemon: Get https://192.168.8.254:5000/v1/_ping: tls: oversized record received with length 20527
配置正確的話,會以下輸出
[root@ct7 ~]# docker pull 192.168.8.254:5000/centos:7
7: Pulling from centos
488a93afa07d: Pull complete
Digest: sha256:88dcdb9b54988129d4b63d98
Status: Downloaded newer image for 192.168.8.254:5000/centos:7
[root@ct7 ~]# docker images
REPOSITORY
192.168.8.254:5000/centos
[root@ct7 ~]# docker run -t -i 192.168.8.254:5000/centos:7 /bin/bash
或者直接
[root@ct7 ~]# docker run -dti 192.168.8.254:5000/centos:7 /bin/bash
Unable to find image '192.168.8.254:5000/centos:7' locally
7: Pulling from centos
488a93afa07d: Pull complete
Digest: sha256:88dcdb9b54988129d4b63d98
Status: Downloaded newer image for 192.168.8.254:5000/centos:7
2fcd581979e9be74cf15b51b
[root@ct7 ~]# docker ps
CONTAINER ID
2fcd581979e9
[root@ct7 ~]# docker attach 2fcd581979e9
[root@243ae3584729 /]# cd
[root@243ae3584729 ~]# uname -a
Linux 243ae3584729 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@243ae3584729 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@243ae3584729 ~]# ip a
1: lo: mtu 65536 qdisc noqueue state UNKNOWN
4: eth0: mtu 1500 qdisc noqueue state UP
7.導入image
docker import ubuntu-14.04-x86_64-minimal.tar.gz
docker
docker
docker import
docker
docker
提示:導入本地鏡像須要先import--->tag--->push
root@router:~#docker import
sha256:7d957a47f7fd2a7ea8353e45
root@router:~#docker
root@router:~#docker push localhost:5000/centos:7
The push refers to a repository [localhost:5000/centos]
6e6b57f1d84d: Pushed
7: digest: sha256:88dcdb9b54988129d4b63d98
8.運行容器
docker run -i -t localhost:5000/centos:7 /bin/bash
root@router:~#docker run -i -t localhost:5000/centos:7 /bin/bash
[root@ce2171a92f1b /]# uname -a
Linux ce2171a92f1b 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@da2ea9c701dc /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@ce2171a92f1b /]# w
USER
[root@ce2171a92f1b /]# df -h
Filesystem
/dev/mapper/docker-8:1-25168265-1da6fb8109b9cfb53a32d071
tmpfs
tmpfs
/dev/sda1
shm
B.daemon方式的Docker Registry 2.0
說明:以前的docker-registry(基於python)已經廢止,最新項目轉爲docker-distribution(基於Go>=1.5)
Notice:
The classical python "Docker Registry" is deprecated, in favor of a new golang implementation. This here is kept for historical purpose, and will not receive any significant work/love any more. You should head to the landing page of the new registry or the "Distribution" github project instead.
This repository's main product is the Docker Registry 2.0 implementation for storing and distributing Docker images. It supersedes the
yum安裝
yum -y install docker-distribution
systemctl enable docker-distribution
systemctl start docker-distribution
[root@ct7 ~]# systemctl status docker-distribution
● docker-distribution.service - v2 Registry server for Docker
6月 11 20:20:58 ct7.example.com systemd[1]: Started v2 Registry server for Docker.
6月 11 20:20:58 ct7.example.com systemd[1]: Starting v2 Registry server for Docker...
6月 11 20:20:58 ct7.example.com registry[2400]: time="2016-06-11T20:20:58+08:00" level=warning m...
6月 11 20:20:58 ct7.example.com registry[2400]: time="2016-06-11T20:20:58+08:00" level=info m...wn"
6月 11 20:20:58 ct7.example.com registry[2400]: time="2016-06-11T20:20:58+08:00" level=info m...wn"
6月 11 20:20:58 ct7.example.com registry[2400]: time="2016-06-11T20:20:58+08:00" level=info m...wn"
6月 11 20:20:58 ct7.example.com registry[2400]: time="2016-06-11T20:20:58+08:00" level=info m...wn"
Hint: Some lines were ellipsized, use -l to show in full.
[root@ct7 ~]# ps -ef|grep distribution
root
root
[root@ct7 ~]# netstat -tunlp|grep registry
tcp6
或者
源碼安裝
1.升級go(>=1.5)
wget
tar -xvf go1.6.2.linux-amd64.tar.gz -C /opt
sudo cat >>/etc/profile <<'HERE'
export
export
export
HERE
source /etc/profile
提示:主要設置GOROOT(安裝路徑),GOPATH(go項目的存放位置,自定義)
root@router:~#go version
go version go1.6.2 linux/amd64
2.安裝docker-distribution
go get -v
一條命令自動git並編譯安裝好,這裏的版本是2.4.1
[root@ct7 ~]# $GOPATH/bin/registry -v
/var/tmp/go/bin/registry github.com/docker/distribution v2.4.1+unknown
3.啓動docker-distribution
mkdir /var/lib/registry #存放registry的目錄必定要存在,不然,在上傳image的時候會報503錯誤
cd $GOPATH
./bin/registry serve .src/github.com/docker/distribution/cmd/registry/config-example.yml
看到以下結果,說明docker-distribution成功運行,默認監聽在5000端口,配置文件能夠根據模板(config-example.yml)來自定義
最好是放到後臺執行
[root@ct7 go]# pwd
/var/tmp/go
[root@ct7 go]# ./bin/registry serve ./src/github.com/docker/distribution/cmd/registry/config-example.yml
WARN[0000] No HTTP secret provided - generated random secret. This may cause problems with uploads if multiple registries are behind a load-balancer. To provide a shared secret, fill in http.secret in the configuration file or set the REGISTRY_HTTP_SECRET environment variable.
INFO[0000] redis not configured
INFO[0000] Starting upload purge in 11m0s
INFO[0000] using inmemory blob descriptor cache
INFO[0000] listening on [::]:5000
[root@ct7 ~]# netstat -tunlp|grep registry
tcp6
https://docs.docker.com/registry/configuration/#list-of-configuration-options
配置示例https://github.com/docker/distribution/blob/master/docs/configuration.md#storage
cat
version: 0.1
log:
storage:
http:
health:
REST API
https://docs.docker.com/registry/spec/api/
http://docker-py.readthedocs.io/en/latest/api/
1.查看repo列表
root@router:~#curl -XGET http://192.168.8.254:5000/v2/_catalog
{"repositories":["centos","consul","elasticsearch","gliderlabs/registrator","rethinkdb","shipyard/shipyard","swarm","ubuntu","zookeeper"]}
2.查看repo中的tag列表
root@router:~#curl -XGET http://192.168.8.254:5000/v2/swarm/tags/list
{"name":"swarm","tags":["latest"]}
root@router:~#curl -XGET http://192.168.8.254:5000/v2/consul/tags/list
{"name":"consul","tags":["0.6.4","latest"]}
3.刪除鏡像
docker官方鑑於v2 版設計的安全性與開發需求成本和磁盤的廉價性,至今沒有出和v2相似直接刪除並釋放磁盤空間的方法,以致於你第三方的shipyard等目前也只支持v1倉庫,這裏簡單介紹一種刪除的方法
i.啓用registry刪除並重啓
/etc/docker-distribution/registry/config.yml
version: 0.1
log:
storage:
http:
systemctl restart docker-distribution
在storage段啓用delete
ii.查找到對應image的Digest
Note
When deleting a manifest from a registry version 2.3 or later, the following header must be used when HEAD
or GET
-ing the manifest to obtain the correct digest to delete:
Accept: application/vnd.docker.distribution.manifest.v2+json
注意: 刪除時必定要帶上v2的Header,不然會刪除失敗
root@router:~#curl -I -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X GET 192.168.8.254:5000/v2/alpine/manifests/latest
HTTP/1.1 200 OK
Content-Length: 528
Content-Type: application/vnd.docker.distribution.manifest.v2+json
Docker-Content-Digest: sha256:4b8403bacd7f331e2016aaeb
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:4b8403bacd7f331e2016aaeb
Date: Fri, 14 Oct 2016 00:16:37 GM
上面是帶了v2頭的,下面是沒帶v2頭的,二者的Digest值明顯不一樣,這也是不少同窗在刪除的時候出現UNKNOWN MANIFEST的錯誤提示的緣由。
root@router:~#curl -I -X GET 192.168.8.254:5000/v2/alpine/manifests/latest
HTTP/1.1 200 OK
Content-Length: 2133
Content-Type: application/vnd.docker.distribution.manifest.v1+prettyjws
Docker-Content-Digest: sha256:df73ed0973f15f40496c1483
Docker-Distribution-Api-Version: registry/2.0
Etag: "sha256:df73ed0973f15f40496c1483
Date: Fri, 14 Oct 2016 00:17:41 GMT
iii.API刪除
root@router:~#curl -I -H "Accept: application/vnd.docker.distribution.manifest.v2+json" -X DELETE 192.168.8.254:5000/v2/alpine/manifests/sha256:4b8403bacd7f331e2016aaeb
HTTP/1.1 202 Accepted
Docker-Distribution-Api-Version: registry/2.0
Date: Fri, 14 Oct 2016 00:24:06 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8
iv.垃圾回收
root@router:~#registry garbage-collect /etc/docker-distribution/registry/config.yml
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/4b/4b8403bacd7f331e2016aaeb
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/c0/c0cb142e43453ebb1f82b905
INFO[0000] Deleting blob: /docker/registry/v2/blobs/sha256/ee/ee4603260daafe1a8c2f3b78
python腳本
A list of methods and URIs are covered in the table below:
Method | Path | Entity | Description |
---|---|---|---|
GET | /v2/ |
Base | Check that the endpoint implements Docker Registry API V2. |
GET | /v2//tags/list |
Tags | Fetch the tags under the repository identified by name . |
GET | /v2//manifests/ |
Manifest | Fetch the manifest identified by name reference where reference can be a tag or digest. A HEAD request can also be issued to this endpoint to obtain resource information without receiving all data. |
PUT | /v2//manifests/ |
Manifest | Put the manifest identified by name reference where reference can be a tag or digest. |
DELETE | /v2//manifests/ |
Manifest | Delete the manifest identified by name reference . Note that a manifest can digest . |
GET | /v2//blobs/ |
Blob | Retrieve the blob from the registry identified by digest . A HEAD |
DELETE | /v2//blobs/ |
Blob | Delete the blob identified by name digest |
POST | /v2//blobs/uploads/ |
Initiate Blob Upload | Initiate a resumable blob upload. If successful, an upload location will be provided to complete the upload. Optionally, if the digest parameter is present, the request body will be used to complete the upload in a single request. |
GET | /v2//blobs/uploads/ |
Blob Upload | Retrieve status of upload identified by uuid . The primary purpose of this endpoint is to resolve the current status of a resumable upload. |
PATCH | /v2//blobs/uploads/ |
Blob Upload | Upload a chunk of data for the specified upload. |
PUT | /v2//blobs/uploads/ |
Blob Upload | Complete the upload specified by uuid , optionally appending the body as the final chunk. |
DELETE | /v2//blobs/uploads/ |
Blob Upload | Cancel outstanding upload processes, releasing associated resources. If this is not called, the unfinished uploads will eventually timeout. |
GET | /v2/_catalog |
Catalog | Retrieve a sorted, json list of repositories available in the registry. |