Docker3本地仓库的搭建

什么是仓库
Docker仓库是用来包含镜像的位置,docker提供一个注册服务器(register)
一般有很多别人打包好的镜像,直接用docker pull拉取
使用的默认仓库是Docker Hub公共仓库
一.1.libseccomp搭建本地私有仓库

[root@server1 ~]# docker rm -f brave_mahavira fervent_goldstine  admiring_burnell  unruffled_leavitt  infallible_montalcini 

先把刚才的容器都删除

[root@server1 docker]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
ddad3d7c1e96: Pull complete 
6eda6749503f: Pull complete 
363ab70c2143: Pull complete 
5b94580856e6: Pull complete 
12008541203a: Pull complete 
Digest: sha256:aba2bfe9f0cff1ac0618ec4a54bfefb2e685bbac67c8ebaf3b6405929b3e616f
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest

联网拉取仓库

[root@server1 docker]# docker history registry:latest 
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
1fd8e1b0bb7e        2 months ago        /bin/sh -c #(nop)  CMD ["/etc/docker/registr…   0B                  
<missing>           2 months ago        /bin/sh -c #(nop)  ENTRYPOINT ["/entrypoint.…   0B                  
<missing>           2 months ago        /bin/sh -c #(nop) COPY file:507caa54f88c1f38…   155B                
<missing>           2 months ago        /bin/sh -c #(nop)  EXPOSE 5000                  0B                  
<missing>           2 months ago        /bin/sh -c #(nop)  VOLUME [/var/lib/registry]   0B                  
<missing>           2 months ago        /bin/sh -c #(nop) COPY file:4544cc1555469403…   295B                
<missing>           2 months ago        /bin/sh -c #(nop) COPY file:21256ff7df5369f7…   20.1MB              
<missing>           2 months ago        /bin/sh -c set -ex     && apk add --no-cache…   549kB               
<missing>           2 months ago        /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B                  
<missing>           2 months ago        /bin/sh -c #(nop) ADD file:282b9d56236cae296…   5.62MB 

可以看到端口是5000

[root@server1 docker]# docker run -d --name registry -p 5000:5000 registry
78db2b26987055e778433aa1a56690ac12c26c4dfebf84e63a3194ac79d2d867

运行仓库,映射端口5000,取名为registry
此时的仓库无认证无加密

[root@server1 docker]# docker tag `yakexi007/game2048:latest localhost:5000/game2048:latest`

修改镜像的名字,指定上传位置

[root@server1 docker]# docker push localhost:5000/game2048:latest 
The push refers to repository [localhost:5000/game2048]
88fca8ae768a: Pushed 
6d7504772167: Pushed 
192e9fad2abc: Pushed 
36e9226e74f8: Pushed 
011b303988d2: Pushed 
latest: digest: sha256:8a34fb9cb168c420604b6e5d32ca6d412cb0d533a826b313b190535c03fe9390 size: 1364

上传给仓库成功

cd /var/lib/docker/volumes/6655adff9e0962436c3a13df0215ebf956c9c0570bea0acd9c14eaea50fa4627/_data/
ls -R

可以看到每层都在此

[root@server1 ~]# docker rmi localhost:5000/game2048:latest 
Untagged: localhost:5000/game2048:latest
Untagged: localhost:5000/game2048@sha256:8a34fb9cb168c420604b6e5d32ca6d412cb0d533a826b313b190535c03fe9390
[root@server1 ~]# docker pull localhost:5000/game2048:latest
latest: Pulling from game2048
Digest: sha256:8a34fb9cb168c420604b6e5d32ca6d412cb0d533a826b313b190535c03fe9390
Status: Downloaded newer image for localhost:5000/game2048:latest
localhost:5000/game2048:latest
[root@server1 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                       NAMES
78db2b269870        registry            "/entrypoint.sh /etc…"   11 minutes ago      Up 11 minutes       0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   registry

把本地的删除,从仓库拉取2048
2. 重新开启一台虚拟机安装好docker

[root@server1 ~]# cd /etc/docker/
[root@server1 docker]# ls
key.json
[root@server1 docker]# touch daemon.json
[root@server1 docker]# vim daemon.json 
[root@server1 docker]# systemctl reload docker.service 
# vim 中的内容
{
        "insecure-registries" : ["172.25.250.11:5000"]
}

再次查看docker info

 Insecure Registries:
  172.25.250.11:5000
  127.0.0.0/8
 Live Restore Enabled: false

强制走11的非安全端口

[root@server1 ~]# scp /etc/sysctl.d/docker.conf root@172.25.250.12:/etc/sysctl.d/
root@172.25.250.12's password: 
docker.conf     

刚才忘记解决server2桥接的问题

sysctl --system

server2执行此使之生效
重新添加端口

vim /etc/docker/daemon.json
{
        "insecure-registries" : ["172.25.250.11:5000"]
}

重启docker,查看dockerinfo

 Insecure Registries:
  172.25.250.11:5000
  127.0.0.0/8
 Live Restore Enabled: false
docker pull 172.25.250.11:5000/game2048:latest
[root@server2 ~]# docker images 
REPOSITORY                    TAG       IMAGE ID       CREATED       SIZE
172.25.250.11:5000/game2048   latest    19299002fdbe   4 years ago   55.5MB

拉取成功

[root@server2 ~]# docker tag 172.25.250.11:5000/game2048:latest game2048

重新起名

[root@server2 ~]# docker rmi 172.25.250.11:5000/game2048:latest 
Untagged: 172.25.250.11:5000/game2048:latest
Untagged: 172.25.250.11:5000/game2048@sha256:8a34fb9cb168c420604b6e5d32ca6d412cb0d533a826b313b190535c03fe9390
[root@server2 ~]# docker images 
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
game2048     latest    19299002fdbe   4 years ago   55.5MB

删除之前的,这是最简单的仓库,模拟了上传和下载,但是作为仓库应该具有加密等策略

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值