docker-registry 是官方提供的工具,可以用于构建私有的镜像仓库。
[root@node01 install]# docker pull registry:2
2: Pulling from library/registry
c87736221ed0: Pulling fs layer
1cc8e0bb44df: Pulling fs layer
54d33bcb37f5: Pulling fs layer
e8afc091c171: Waiting
b4541f6d3db6: Waiting
2: Pulling from library/registry
c87736221ed0: Pull complete
1cc8e0bb44df: Pull complete
54d33bcb37f5: Pull complete
e8afc091c171: Pull complete
b4541f6d3db6: Pull complete
Digest: sha256:77a8fb00c00b99568772a70f0863f6192ff2635e4af4e22e4d9c622edeb5f2de
Status: Downloaded newer image for registry:2
查看
[root@node01 install]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
172.30.168.123:5000/hello-world/cakephp-mysql-example latest 8fcec8055f89 16 hours ago 647MB
5eb65a43b4dd 16 hours ago 643MB
centos/centos 7.2.1511 ac33c8295659 7 days ago 195MB
centos/centos dev ac33c8295659 7 days ago 195MB
root/ubuntu v2 2103c03d422e 7 days ago 144MB
httpd latest e77c77f17b46 7 days ago 140MB
nginx latest 719cd2e3ed04 8 days ago 109MB
ubuntu 16.04 2a697363a870 4 weeks ago 119MB
centos/php-70-centos7 e77118e72bde 2 months ago 606MB
centos/mysql-57-centos7 e35b3f7a4ea0 2 months ago 452MB
centos 7.2.1511 9aec5c5fe4ba 3 months ago 195MB
registry 2 f32a97de94e1 3 months ago 25.8MB
hello-world latest fce289e99eb9 5 months ago 1.84kB
openshift/hello-openshift latest 7af3297a3fb4 14 months ago 6.09MB
openshift/origin-sti-builder v1.5.1 e487ac1903b6 2 years ago 617MB
openshift/origin-deployer v1.5.1 0f23b83cad80 2 years ago 617MB
openshift/origin-docker-registry v1.5.1 345b59149571 2 years ago 428MB
openshift/origin-haproxy-router v1.5.1 02a2dd43884b 2 years ago 739MB
openshift/origin-pod v1.5.1 aad02d5e14b9 2 years ago 1.14MB
ubuntu 15.10 9b9cb95443b5 2 years ago 137MB
training/webapp latest 6fae60ef3446 4 years ago 349MB
用一下命令启动容器
[root@node01 install]# docker run -d -p 5000:5000 --restart=always --name registry -v /opt/registry:/var/lib/registry registry:2
987ce17a2549d1a17cc5f66322fba06db59f026fcb8c5879f608a38d38155dee
[root@node01 install]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
987ce17a2549 registry:2 "/entrypoint.sh /etc…" 7 seconds ago Up 3 seconds 0.0.0.0:5000->5000/tcp registry
a218f672c488 centos/mysql-57-centos7 "container-entrypoin…" 17 hours ago Up 17 hours k8s_mysql.e6ad6abe_mysql-1-mzjhv_hello-world_8197cd66-91b5-11e9-bd87-000c29c44e6d_7ee61d7f
262f9ed63a38 openshift/origin-pod:v1.5.1 "/pod" 17 hours ago Up 17 hours k8s_POD.b460fe8c_mysql-1-mzjhv_hello-world_8197cd66-91b5-11e9-bd87-000c29c44e6d_395486c0
dde5c419d1be openshift/hello-openshift "/hello-openshift" 17 hours ago Up 17 hours k8s_hello-openshift.ce03e6af_hello-openshift-1-vb777_hello-world_be4206e2-91a1-11e9-bd87-000c29c44e6d_ac337134
1bbe7acd7bbc openshift/hello-openshift "/hello-openshift" 17 hours ago Up 17 hours k8s_hello-openshift.6412e6e8_hello-openshift-1-qw9m7_hello-world-oc_8ae24003-91a4-11e9-bd87-000c29c44e6d_d0d0fa08
8e6daefe990c openshift/origin-pod:v1.5.1 "/pod" 17 hours ago Up 17 hours k8s_POD.4b6921c2_hello-openshift-1-vb777_hello-world_be4206e2-91a1-11e9-bd87-000c29c44e6d_c2eca284
7465047d59fb openshift/origin-docker-registry:v1.5.1 "/bin/sh -c 'DOCKER_…" 17 hours ago Up 17 hours k8s_registry.11a10546_docker-registry-1-ncm7p_default_06d56873-91ae-11e9-bd87-000c29c44e6d_b651d975
48e7dfda342b openshift/origin-pod:v1.5.1 "/pod" 17 hours ago Up 17 hours k8s_POD.4b6921c2_hello-openshift-1-qw9m7_hello-world-oc_8ae24003-91a4-11e9-bd87-000c29c44e6d_4f8859ed
aa92345e901a openshift/origin-haproxy-router:v1.5.1 "/usr/bin/openshift-…" 17 hours ago Up 17 hours k8s_router.49c08b1_router01-1-hp6t8_default_e0b817cc-91ac-11e9-bd87-000c29c44e6d_1d8d8f08
e88d7d021574 openshift/origin-pod:v1.5.1 "/pod" 17 hours ago Up 17 hours k8s_POD.a71dfe85_docker-registry-1-ncm7p_default_06d56873-91ae-11e9-bd87-000c29c44e6d_c7b9a62d
ae45bc92df30 openshift/origin-pod:v1.5.1 "/pod" 17 hours ago Up 17 hours k8s_POD.50d4dca2_router01-1-hp6t8_default_e0b817cc-91ac-11e9-bd87-000c29c44e6d_fa3d128b
-v /opt/registry:/var/lib/registry 表示将本地目录/opt/registry映射到仓库容器中的/var/lib/registry目录,该目录中存储仓库中的镜像文件。
1、上传镜像到私有registry
[root@node01 install]# docker pull centos:7.2.1511
7.2.1511: Pulling from library/centos
Digest: sha256:50cca1e74da4b6a4eb4ade029c8fdd4ee8564776801914d9bd89df8c6344add0
Status: Image is up to date for centos:7.2.1511
2、修改一下该镜像的tag
[root@node01 install]# docker tag centos:7.2.1511 node01:5000/os/centos:v7.2
说明:
centos:7.2.1511——是镜像的名称和版本
node01:5000——私库的ip:端口(必须)
/jiangjj/centos:v7.2——文件夹和版本区分
3、上传镜像到我的私有registry
[root@node01 install]# docker push node01:5000/os/centos:v7.2
The push refers to repository [node01:5000/os/centos]
Get https://node01:5000/v2/: http: server gave HTTP response to HTTPS client