CentOS搭建docker-registry仓库

在CentOS上搭建docker私服

环境:

  • IP:
    0.0.0.50(Docker Registry Server)
    0.0.0.59(Docker client )

  • OS: CentOS Linux release 7.2.1511 (Core)

  • Docker Version: Docker version 1.12.0, build 8eab29e


Step 1: 以下操作运行在0.0.0.50(Docker Registry Server)上

安装docker-registry, 运行以下命令
docker run -d -e SETTINGS_FLAVOR=dev -e STORAGE_PATH=/tmp/registry -v /opt/data/registry:/tmp/registry -p 5000:5000 registry

安装,启动好之后,运行访问这个URL来验证是否成功:
[root@ct7 system]# curl http://0.0.0.50:5000/v1/_ping 404 page not found

如果有如下返回值则代表成功,无返回则说明进程没有启动,把所有的container都删除然后在重新启动
docker rm $(docker ps -a -q)
docker run -d -e SETTINGS_FLAVOR=dev -e STORAGE_PATH=/tmp/registry -v /opt/data/registry:/tmp/registry -p 5000:5000 registry


Step 2: 以下操作运行在0.0.0.59(Docker client)上

1.查看当前的images

1
2
3
[root@ct7 system]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gethue/hue latest f7f2abf45534 4 months ago 2.284 GB

2.查看当前所有的container

1
2
3
4
5
[root@ct7 system]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b45fcfb4c4c gethue/hue:latest "bash" 2 weeks ago Up 31 minutes 0.0.0.0:8888->8888/tcp high_lovelace
--container没有起来,运行如下命令:
[root@ct7 system]# docker start 5b45fcfb4c4c

3.查看当前运行的container

1
2
3
[root@ct7 system]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5b45fcfb4c4c gethue/hue:latest "bash" 2 weeks ago Up 34 minutes 0.0.0.0:8888->8888/tcp high_lovelace

4.Create a new image from a container’s changes

1
2
3
4
5
[root@ct7 system]# docker commit 5b45fcfb4c4c 0.0.0.50:5000/hue-v1
sha256:8f41bc37f2b4164c79a9924ca9b6f38581a7ca8f50e60d2ac49818a765c35f09
[root@ct7 system]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
0.0.0.50:5000/hue-v1 latest 8f41bc37f2b4 15 seconds ago 2.57 GB

5.push new image into docker private registry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@ct7 system]# docker push 0.0.0.50:5000/hue-v1
The push refers to a repository [0.0.0.50:5000/hue-v1]
eb8378240c72: Pushed
1e71236cfd2b: Pushed
fccab3c2b82b: Pushed
30c28efdecff: Pushed
634827038ea7: Pushed
8f22c1173848: Pushed
8191da9e7f9a: Pushed
173f1156fe76: Pushed
5b771cc18969: Pushed
ae16cd6221a3: Pushed
7dce18002c8d: Pushed
5f70bf18a086: Pushed
6f8be37bd578: Pushed
9f7ab087e6e6: Pushed
dc109d4b4ccf: Pushed
a7e1c363defb: Pushed
latest: digest: sha256:b9ee12c606e3da3554b3f5df9f88364eb8986b1f6fe1ae625542c8e3343e1627 size: 3691
——————————————————————————————————————————————————————————————————————————————————————
如果push的时候报以下错误时:"server gave HTTP response to HTTPS client"
创建/etc/docker/daemon.json文件,并写入
[root@ct7 system]# more /etc/docker/daemon.json
{ "insecure-registries":["0.0.0.50:5000"] }
然后重启docker:
[root@ct7 system]# service docker restart

6.verify the new image from docker private registry

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--删除old image
[root@ct7 system]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
0.0.0.50:5000/hue-v1 latest 9095f95a6f9f 18 hours ago 2.57 GB
[root@ct7 system]# docker rmi 0.0.0.50:5000/hue-v1
Untagged: 0.0.0.50:5000/hue-v1:latest
Deleted: sha256:9095f95a6f9fb97de276752db6a5dd44bf279b58cfdf4c723c48090b6ef3a5f5
Deleted: sha256:8a560d1d95af6e2436ba2ff73125b383bef343e6e6d4ff45c3dc61352342c7c8
——————————————————————————————————————————————————————————————————————————————————————
--查看docker registry images
[root@ct7 system]# curl http://0.0.0.50:5000/v1/search
404 page not found
网上都用这个curl http://0.0.0.50:5000/v1/search,但是报404 page not found,后查证是v1版本的api查看方式,我们现在的版本是v2,所以用如下方法查看:
curl -X GET http://0.0.0.50:5000/v2/_catalog
[root@ct7 system]# curl -X GET http://0.0.0.50:5000/v2/_catalog
{"repositories":["centos7-python","hue-v1"]}
——————————————————————————————————————————————————————————————————————————————————————
-- pull new images
[root@ct7 system]# docker pull 0.0.0.50:5000/hue-v1
[root@ct7 system]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
0.0.0.50:5000/hue-v2 latest 1905f45f6154 15 hours ago 2.486 GB
0.0.0.50:5000/hue-v1 latest 8f41bc37f2b4 20 hours ago 2.57 GB
由于commit方式不会保存mount的数据,所以需要对应用做如下操作
The commit operation will not include any data contained in volumes mounted inside the container.
root@3201bbe4b443:/home/tony/hue# scp 0.0.0.58:/storage/software/hue/pseudo-distributed.ini /hue/desktop/conf/pseudo-distributed.ini
source /etc/profile
root@3201bbe4b443:/home/tony/hue# /home/tony/hue/start_hue.sh