Docker学习(10)------创建Docker私有镜像库

本文介绍如何在CentOS 7上搭建并使用私有Docker镜像仓库,包括配置Docker服务、推送镜像到本地仓库、从另一台宿主机拉取镜像的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

操作环境

Centos7

Docker version 17.04.0-ce, build 4845c56

操作步骤

1.通过官方的registry来启动本地的镜像库

[root@docker-1 ~]# docker run -d -v /home/registry/:/var/lib/registry -p 5000:5000 --restart=always registry

其中目录/home/registry是作为本地存储镜像的目录

这里还需要修改docker.service里面的参数,设置ExecStart参数如下,添加selinux及insecert-registry参数

ExecStart=/usr/bin/dockerd --graph=/overlay --storage-driver=overlay --selinux-enabled  --insecure-registry=10.10.200.61:5000



2.推送镜像至本地镜像库中

我们先查看现有的image

[root@docker-1 ~]# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
centos6-nginx                     latest              d4518903c036        About an hour ago   440MB
composetest_web                   latest              2f24fcd57f86        4 hours ago         93.7MB
nginx-test                        latest              7a905f867454        5 hours ago         2.89GB
swarm-lnmp                        latest              70ee70991912        6 hours ago         2.81GB
centos6-lnmp-new                  latest              7439837a77ae        24 hours ago        3.08GB
centos6-lnmp                      latest              d91ae7290a71        2 days ago          2.81GB
nginx                             latest              5766334bdaa0        6 days ago          182MB
registry                          latest              136c8b16df20        6 days ago          33.2MB
mysql                             <none>              9546ca122d3a        13 days ago         407MB
redis                             latest              83d6014ac5c8        3 weeks ago         184MB
centos                            centos6             ae5cb7280ec3        4 weeks ago         195MB
centos                            <none>              98d35105a391        4 weeks ago         192MB
python                            3.4-alpine          9ac5db25a0ca        5 weeks ago         82.4MB
alpine                            <none>              4a415e366388        5 weeks ago         3.98MB
registry                          2.5.0               c6c14b3960bd        8 months ago        33.3MB
redis                             <none>              d4deec2c521c        15 months ago       151MB
glusterfs/gluster_fedora          latest              1b5fde5352e3        23 months ago       1.06GB

我们选择centos6-nginx作为推送image,首先对其进行tag操作

[root@docker-1 ~]# docker tag  d4518903c036 10.10.200.61:5000/centos6-nginx

再来查看images

[root@docker-1 ~]# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
10.10.200.61:5000/centos6-nginx   latest              d4518903c036        About an hour ago   440MB
centos6-nginx                     latest              d4518903c036        About an hour ago   440MB
composetest_web                   latest              2f24fcd57f86        4 hours ago         93.7MB
nginx-test                        latest              7a905f867454        5 hours ago         2.89GB
swarm-lnmp                        latest              70ee70991912        6 hours ago         2.81GB
centos6-lnmp-new                  latest              7439837a77ae        24 hours ago        3.08GB
centos6-lnmp                      latest              d91ae7290a71        2 days ago          2.81GB
nginx                             latest              5766334bdaa0        6 days ago          182MB
registry                          latest              136c8b16df20        6 days ago          33.2MB
mysql                             <none>              9546ca122d3a        13 days ago         407MB
redis                             latest              83d6014ac5c8        3 weeks ago         184MB
centos                            centos6             ae5cb7280ec3        4 weeks ago         195MB
centos                            <none>              98d35105a391        4 weeks ago         192MB
python                            3.4-alpine          9ac5db25a0ca        5 weeks ago         82.4MB
alpine                            <none>              4a415e366388        5 weeks ago         3.98MB
registry                          2.5.0               c6c14b3960bd        8 months ago        33.3MB
redis                             <none>              d4deec2c521c        15 months ago       151MB
glusterfs/gluster_fedora          latest              1b5fde5352e3        23 months ago       1.06GB


3.推送images

[root@docker-1 ~]# docker push 10.10.200.61:5000/centos6-nginx
The push refers to a repository [10.10.200.61:5000/centos6-nginx]
0888ed09f997: Pushed 
cc98c33b9e0b: Pushed 
latest: digest: sha256:16b5b33e75675c4dfc1be5bc578398a43d925f0351197b0ec6ba2f5309316f42 size: 742

4.查看私有镜像库中的images

[root@docker-1 ~]# curl http://10.10.200.61:5000/v2/_catalog
{"repositories":["centos6-nginx"]}

5.在另外一台docker宿主机,pull该私有镜像库中的images

首先在docker.service中设置ExecStart参数

ExecStart=/usr/bin/dockerd --graph=/home/docker --storage-driver=overlay --selinux-enabled  --insecure-registry=10.10.200.61:5000

查看10.10.200.61私有镜像库的images

[root@docker-2 ~]# curl  http://10.10.200.61:5000/v2/_catalog
{"repositories":["centos6-nginx"]}

pull image

[root@docker-2 ~]# docker pull 10.10.200.61:5000/centos6-nginx
Using default tag: latest
latest: Pulling from centos6-nginx
d887009e9d1a: Pull complete 
923589dd105a: Pull complete 
Digest: sha256:16b5b33e75675c4dfc1be5bc578398a43d925f0351197b0ec6ba2f5309316f42
Status: Downloaded newer image for 10.10.200.61:5000/centos6-nginx:latest

查看该宿主机中的images

root@docker-2 ~]# docker images
REPOSITORY                        TAG                 IMAGE ID            CREATED             SIZE
10.10.200.61:5000/centos6-nginx   latest              d4518903c036        About an hour ago   440 MB
mysql                             <none>              9546ca122d3a        13 days ago         407 MB
centos                            centos6             ae5cb7280ec3        4 weeks ago         195 MB
centos                            <none>              98d35105a391        4 weeks ago         192 MB
alpine                            <none>              4a415e366388        5 weeks ago         3.98 MB
redis                             <none>              d4deec2c521c        15 months ago       151 MB



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值