首先查看原有的镜像
#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
web new dcca36f7ba99 7 days ago 269.2 MB
testweb new 890b0964f807 7 days ago 194.6 MB
centos centos6 a3c09d36ab4a 3 weeks ago 194.6 MB
centos latest 970633036444 3 weeks ago 196.7 MB
2、然后获取官方 registry 镜像
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#docker pull registry
Using default tag: latest
latest: Pulling from library/registry
e110a4a17941: Pull complete
2ee5ed28ffa7: Pull complete
d1562c23a8aa: Pull complete
06ba8e23299f: Pull complete
802d2a9c64e8: Pull complete
Digest: sha256:1b68f0d54837c356e353efb04472bc0c9a60ae1c8178c9ce076b01d2930bcc5d
Status: Downloaded newer image for registry:latest
查看是否pull成功
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
web new dcca36f7ba99 7 days ago 269.2 MB
testweb new 890b0964f807 7 days ago 194.6 MB
centos centos6 a3c09d36ab4a 3 weeks ago 194.6 MB
centos latest 970633036444 3 weeks ago 196.7 MB
registry latest c6c14b3960bd 3 weeks ago 33.28 MB #表示已经成功了
3、基于私有仓库镜像运行容器
1
2
3
4
5
6
7
8
#docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
a08a501701eba97c8f56fbc9b63e6f356dec1283b6c07f0f931639b4514b3838
查看运行的容器
#docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0d79735868cd centos "/bin/bash" Less than a second ago Exited (137) Less than a second ago centos7
43b66a52f166 centos:centos6 "/bin/bash" Less than a second ago Exited (137) Less than a second ago server1
a08a501701eb registry "/entrypoint.sh /etc/" 3 seconds ago Up 3 seconds 0.0.0.0:5000->5000/tcp high_bardeen #已经运行了
#curl 127.0.0.1:5000/v1/search #不知道什么原因,我测试的时候使用curl提示404
404 page not found
#curl 127.0.0.1:5000/v1/search #网上有一个例子,提示如下信息;
{"num_results": 0, "query": "", "results": []} //私有仓库为空,没有提交新镜像到仓库中
4、创建镜像链接或为基础镜像打个标签
1
2
3
4
5
6
7
8
9
#docker tag registry 127.0.0.1:5000/ssh #这里选择为registry镜像打标签
[iyunv@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
web new dcca36f7ba99 7 days ago 269.2 MB
testweb new 890b0964f807 7 days ago 194.6 MB
centos centos6 a3c09d36ab4a 3 weeks ago 194.6 MB
centos latest 970633036444 3 weeks ago 196.7 MB
127.0.0.1:5000/ssh latest c6c14b3960bd 3 weeks ago 33.28 MB
registry latest c6c14b3960bd 3 weeks ago 33.28 MB
5、提交镜像到本地私有仓库中
1
2
3
4
5
6
7
8
9
10
11
#docker push 127.0.0.1:5000/ssh
The push refers to a repository [127.0.0.1:5000/ssh]
3bb5bc5ad373: Pushed
35039a507f7a: Pushed
d00444e19d65: Pushed
aa3a31ee27f3: Pushed
4fe15f8d0ae6: Pushed
latest: digest: sha256:51d8869caea35f58dd6a2309423ec5382f19c4e649b5d2c0e3898493f42289d6 size: 1363
注意:没报错,应该push成功了!查看私有仓库是否存在对应的镜像,依然提示404
#curl 127.0.0.1:5000/v1/search
404 page not found
二、测试私有库是否可用
说明:centos6.x x86_64 IP:10.0.90.26 docker 版本:Docker version 1.7.1, build 786b29d/1.7.1
1、在另外一台centos6.x系统测试pull功能,如下:
#docker pull 10.0.90.25:5000/ssh
Error response from daemon: invalid registry endpoint https://10.0.90.25:5000/v0/: unable to ping registry endpoint https://10.0.90.25:5000/v0/
v2 ping attempt failed with error: Get https://10.0.90.25:5000/v2/: tls: oversized record received with length 20527
v1 ping attempt failed with error: Get https://10.0.90.25:5000/v1/_ping: tls: oversized record received with length 20527. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 10.0.90.25:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/10.0.90.25:5000/ca.crt
报错了,根据提示需要创建证书或者添加--insecure-registry 10.0.90.25:5000作为docker启动参数,先测试更换启动参数,看是否可以解决问题,先kill掉docker进程,再添加参数启动,如下
#/usr/bin/docker -d --insecure-registry 10.0.90.25:5000 &
# ps aux | grep docker
root 1980 0.1 1.5 583928 16184 pts/0 Sl 17:16 0:02 /usr/bin/docker -d --insecure-registry 10.0.90.25:5000
已经启动了,继续pull私有仓库的镜像到本地
#docker pull 10.0.90.25:5000/ssh
INFO[0006] POST /v1.19/images/create?fromImage=10.0.90.25%3A5000%2Fssh%3Alatest
latest: Pulling from 10.0.90.25:5000/ssh
9b7301678506: Pull complete
d912f6ed534e: Pull complete
664daba008e5: Pull complete
33e9a84661e7: Pull complete
5366f93a80af: Pull complete
8d1f9ff6843f: Pull complete
79a50c6b6f41: Pull complete
94c689ffd50b: Pull complete
ad8da6d14f6d: Pull complete
Digest: sha256:a80c28adf17579da93b681893f663bf7625e0012c53c304294f1c328a0d27d9b
Status: Downloaded newer image for 10.0.90.25:5000/ssh:latest
查看
#docker images
INFO[2107] GET /v1.19/images/json
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos centos6 429d551fa7ee Less than a second ago 194.6 MB
centos latest b62568c09fa0 Less than a second ago 196.7 MB
10.0.90.25:5000/ssh latest ad8da6d14f6d Less than a second ago 33.28 MB
可以看到pull成功了。
#docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
web new dcca36f7ba99 7 days ago 269.2 MB
testweb new 890b0964f807 7 days ago 194.6 MB
centos centos6 a3c09d36ab4a 3 weeks ago 194.6 MB
centos latest 970633036444 3 weeks ago 196.7 MB
127.0.0.1:5000/ssh latest c6c14b3960bd 3 weeks ago 33.28 MB
registry latest c6c14b3960bd 3 weeks ago 33.28 MB
[iyunv@docker ~]# docker tag centos:centos6 127.0.0.1:5000/centos6 #标记centos6镜像为127.0.0.1:5000/centos6
[iyunv@docker ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
web new dcca36f7ba99 7 days ago 269.2 MB
testweb new 890b0964f807 7 days ago 194.6 MB
127.0.0.1:5000/centos6 latest a3c09d36ab4a 3 weeks ago 194.6 MB
centos centos6 a3c09d36ab4a 3 weeks ago 194.6 MB
centos latest 970633036444 3 weeks ago 196.7 MB
127.0.0.1:5000/ssh latest c6c14b3960bd 3 weeks ago 33.28 MB
registry latest c6c14b3960bd 3 weeks ago 33.28 MB
上传到私有库
[iyunv@docker ~]# docker push 127.0.0.1:5000/centos6 #会看到push的进度
The push refers to a repository [127.0.0.1:5000/centos6]
6b5c6954e3d5: Pushing [==========================> ] 102.6 MB/194.6 MB
push完成之后,显示如下信息
[iyunv@docker ~]# docker push 127.0.0.1:5000/centos6
The push refers to a repository [127.0.0.1:5000/centos6]
6b5c6954e3d5: Pushed
latest: digest: sha256:f7378a219c2a1d189e2e6a9bedc1b05ed3bb60de32ad24a9ad8e8ef8152c52c4 size: 529
#docker pull 10.0.90.25:5000/centos6 #pull进度可以看到
INFO[2640] POST /v1.19/images/create?fromImage=10.0.90.25%3A5000%2Fcentos6%3Alatest
latest: Pulling from 10.0.90.25:5000/centos6
3690474eb5b4: Pull complete
c12ea02d7eb2: Extracting [===================================> ] 48.46 MB/68.76 MB
334af8693ca8: Download complete
273a1eca2d3a: Download complete
成功之后,显示如下:
#docker pull 10.0.90.25:5000/centos6
INFO[2640] POST /v1.19/images/create?fromImage=10.0.90.25%3A5000%2Fcentos6%3Alatest
latest: Pulling from 10.0.90.25:5000/centos6
3690474eb5b4: Pull complete
c12ea02d7eb2: Pull complete
334af8693ca8: Pull complete
273a1eca2d3a: Pull complete
Digest: sha256:3e4b73f8e13d8527f06cfd34d6c2cfdd16cce76ee7215a29379ae82015b312c9
Status: Downloaded newer image for 10.0.90.25:5000/centos6:latest
查看新pull的centos6镜像
# docker images
INFO[2650] GET /v1.19/images/json
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
10.0.90.25:5000/centos6 latest 273a1eca2d3a Less than a second ago 194.6 MB
centos centos6 429d551fa7ee Less than a second ago 194.6 MB
centos latest b62568c09fa0 Less than a second ago 196.7 MB
10.0.90.25:5000/ssh latest ad8da6d14f6d Less than a second ago 33.28 MB
如上信息,可以看到centos6已经在镜像列表中了!
使用该镜像创建一个容器,进行测试
#docker run -d -it --privileged=false -p 80:80 --name webserver 10.0.90.25:5000/centos6 /bin/bash
INFO[2804] POST /v1.19/containers/create?name=webserver
63e4642a253a592bcf0eb3a9dd12a6363eb7c018b00eced66b9d20c1f4ca0898
INFO[2804] POST /v1.19/containers/63e4642a253a592bcf0eb3a9dd12a6363eb7c018b00eced66b9d20c1f4ca0898/start
[iyunv@test ~]# docker ps -a
INFO[2810] GET /v1.19/containers/json?all=1
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
63e4642a253a 10.0.90.25:5000/centos6 "/bin/bash" 6 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp webserver
进入该容器
# docker attach 63e4642a253a
INFO[2838] GET /v1.19/containers/63e4642a253a/json
INFO[2838] POST /v1.19/containers/63e4642a253a/resize?h=68&w=207
INFO[2838] POST /v1.19/containers/63e4642a253a/attach?stderr=1&stdin=1&stdout=1&stream=1
[iyunv@63e4642a253a /]#
安装httpd并启动
[iyunv@63e4642a253a /]# yum install httpd -y
[iyunv@63e4642a253a ~]# service httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.1 for ServerName
[ OK ]
[iyunv@63e4642a253a ~]# netstat -tunlp #端口已经启动
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 :::80 :::* LISTEN 119/httpd
Error response from daemon: invalid registry endpoint https://10.0.90.25:5000/v0/: unable to ping registry endpoint https://10.0.90.25:5000/v0/
v2 ping attempt failed with error: Get https://10.0.90.25:5000/v2/: tls: oversized record received with length 20527
v1 ping attempt failed with error: Get https://10.0.90.25:5000/v1/_ping: tls: oversized record received with length 20527. If this private registry supports only HTTP or HTTPS with an unknown CA certificate, please add `--insecure-registry 10.0.90.25:5000` to the daemon's arguments. In the case of HTTPS, if you have access to the registry's CA certificate, no need for the flag; simply place the CA certificate at /etc/docker/certs.d/10.0.90.25:5000/ca.crt
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process