Docker构建私有registry

1.拉取registry镜像

[root@localhost ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
cbdbe7a5bc2a: Pull complete 
47112e65547d: Pull complete 
46bcb632e506: Pull complete 
c1cc712bcecd: Pull complete 
3db6272dcbfa: Pull complete 
Digest: sha256:8be26f81ffea54106bae012c6f349df70f4d5e7e2ec01b143c46e2c03b9e551d
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest

2.开启registry容器

–restart 设置容器的重启策略,以决定在容器退出时,Docker守护进程是否重启刚刚退出的容器。

[root@localhost ~]# docker run -d --restart=always --name registry -v /opt/registry/:/var/lib/registry -p 5000:5000 2d4f4b5309b1
a46eb9b32f0fa79af829ff8e8f7969a6f4445039372075d730b5b4bba7eda4ba
[root@localhost ~]# 

3.修改配置文件

[root@localhost ~]# vim /etc/docker/daemon.json 
[root@localhost ~]# cat /etc/docker/daemon.json 
{
	"registry-mirrors":["https://registry.docker-cn.com"],
	"insecure-registries": ["192.168.153.176:5000"]
}

4.重启docker服务

[root@localhost ~]# systemctl restart docker

5.制作本地镜像并push到registry中

5.1先给镜像打标签成标准格式

[root@localhost ~]# docker tag nginx:latest 192.168.153.176:5000/frank:v1

5.2 然后push到registry中

[root@localhost ~]# docker push 192.168.153.176:5000/frank/centos6.9:v1
The push refers to repository [192.168.153.176:5000/frank/centos6.9:v1]
b9e73ac5343e: Pushed 
5887d03dfc3d: Pushed 
e3a971c30b12: Pushed 
32048dd980c7: Pushed 
f5600c6330da: Pushed 
v1: digest: sha256:bb84ff0786cd1dbde780d84f6bf76bfdef36fe8ffa658f7f5c48e39363b4d500 size: 1362
[root@localhost ~]# 

6. 异地进行pull镜像

6.1 克隆虚拟机并删除镜像

克隆出一台虚拟机,删除克隆虚拟机上的所有镜像
删除镜像命令

[root@localhost ~]# docker image rm -f `docker image ls -a -q`

6.2 拉取私有registry的镜像

拉取镜像
root@localhost ~]# docker pull 192.168.153.176:5000/frank/centos6.9:v1
v1: Pulling from frank/centos6.9
831490506c47: Pull complete 
Digest: sha256:7e172600dff1903f186061ce5f5295664ec9942ca120e4e5b427ddf01bb2b35b
Status: Downloaded newer image for 192.168.153.176:5000/frank/centos6.9:v1
192.168.153.176:5000/frank/centos6.9:v1

查看镜像已经拉取成功
[root@localhost ~]# docker images
REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
registry                               latest              2d4f4b5309b1        5 months ago        26.2MB
192.168.153.176:5000/frank/centos6.9   v1                  2199b8eb8390        20 months ago       195MB
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值