[root@ct7 ~]# dao pull ubuntu:16.04
Dao from DaoCloud
Initializing, Please wait a minute
Using default tag: latest
latest: Pulling from daocloud/daocloud-toolset
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)
WARNING
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. |