Docker私有仓库的搭建

下载registry镜像

[root@server1 ~]# docker pull registry:2  ##l拉去镜像
2: Pulling from library/registry
c87736221ed0: Pull complete 
1cc8e0bb44df: Pull complete 
54d33bcb37f5: Pull complete 
e8afc091c171: Pull complete 
b4541f6d3db6: Pull complete 
Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146
Status: Downloaded newer image for registry:2
[root@server1 ~]# docker images  ##查看镜像拉取是否成功
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
<none>                   <none>              7b24b4e0abc4        20 hours ago        308MB
nginx                    latest              f68d6e55e065        10 days ago         109MB
registry                 2                   f32a97de94e1        4 months ago        25.8MB
busybox                  latest              59788edf1f3e        9 months ago        1.15MB
game2048                 latest              19299002fdbe        2 years ago         55.5MB
ubuntu                   latest              07c86167cdc4        3 years ago         188MB
rhel7                    latest              0a3eb3fde7fd        5 years ago         140MB
gcr.io/distroless/base   latest              9a255d5fe262        49 years ago        16.8MB
[root@server1 ~]# docker history registry:2  ##查看镜像的内容
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
f32a97de94e1        4 months ago        /bin/sh -c #(nop)  CMD ["/etc/docker/registr…   0B                  
<missing>           4 months ago        /bin/sh -c #(nop)  ENTRYPOINT ["/entrypoint.…   0B                  
<missing>           4 months ago        /bin/sh -c #(nop) COPY file:507caa54f88c1f38…   155B                
<missing>           4 months ago        /bin/sh -c #(nop)  EXPOSE 5000                  0B                  
<missing>           4 months ago        /bin/sh -c #(nop)  VOLUME [/var/lib/registry]   0B                  
<missing>           4 months ago        /bin/sh -c #(nop) COPY file:4544cc1555469403…   295B                
<missing>           4 months ago        /bin/sh -c #(nop) COPY file:21256ff7df5369f7…   20.1MB              
<missing>           4 months ago        /bin/sh -c set -ex     && apk add --no-cache…   1.29MB              
<missing>           4 months ago        /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B                  
<missing>           4 months ago        /bin/sh -c #(nop) ADD file:38bc6b51693b13d84…   4.41MB      

运行此容器

[root@server1 ~]# docker run -d --name registry -p 5000:5000 -v /opt/registry:/var/lib/registry registry:2  ##创建并运行容器,设置数据卷,并做端口映射
46102f2625c0cf275ee3621ea6b7a823ecca58fe71fbfe0de83c36b670a0d8bc
[root@server1 ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
46102f2625c0        registry:2          "/entrypoint.sh /etc…"   7 seconds ago       Up 5 seconds        0.0.0.0:5000->5000/tcp   registry
[root@server1 ~]# docker volume ls
DRIVER              VOLUME NAME
local               c62ac1ecc98e852b325dbfe2d463524c6946073e1ffdb5324c0e64fb76a09a5e
[root@server1 ~]# netstat -antlp |grep 5000  ##查看5000端口是否开启
tcp6       0      0 :::5000                 :::*                    LISTEN      2368/docker-proxy   

上传镜像到本地仓库

[root@server1 ~]# docker tag nginx:latest localhost:5000/nginx  
[root@server1 ~]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
<none>                   <none>              7b24b4e0abc4        20 hours ago        308MB
nginx                    latest              f68d6e55e065        10 days ago         109MB
localhost:5000/nginx     latest              f68d6e55e065        10 days ago         109MB
registry                 2                   f32a97de94e1        4 months ago        25.8MB
busybox                  latest              59788edf1f3e        9 months ago        1.15MB
game2048                 latest              19299002fdbe        2 years ago         55.5MB
ubuntu                   latest              07c86167cdc4        3 years ago         188MB
rhel7                    latest              0a3eb3fde7fd        5 years ago         140MB
gcr.io/distroless/base   latest              9a255d5fe262        49 years ago        16.8MB
[root@server1 ~]# docker push localhost:5000/nginx  ##镜像上传到本地仓库
[root@server1 ~]# curl localhost:5000/v2/_catalog  ##查看上传是否成功
{"repositories":["nginx"]}

查看其数据卷挂载点

[root@server1 ~]# cd /opt/registry/
[root@server1 registry]# ls
docker
[root@server1 registry]# cd docker/
[root@server1 docker]# ls
registry
[root@server1 docker]# cd registry/
[root@server1 registry]# ls
v2
[root@server1 registry]# tree .  ##查看数据
    └── repositories
        └── nginx
            ├── _layers
            │   └── sha256
            │       ├── 0b760b431b11d38c41e06c6dabd4014ec34b686f7b83c94b18b15e9864aa0777
            │       │   └── link
            │       ├── d2e987ca226748abfe1bcdf1d2488a9bcd864fd0cc016d72635fc1ff3217b3e8
            │       │   └── link
            │       ├── f68d6e55e06520f152403e6d96d0de5c9790a89b4cfc99f4626f6814

此时创建的私有仓库远程主机无法使用,并且不够安全,此时则可以采用私有仓库加证书加密的方式来创建私有仓库

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值