搭建docker私有仓库

搭建docker的私有仓库

一、下载docker的私有仓库镜像

接上篇,安装完docker后,可通过docker pull将操作系统以及常用服务

[root@localhost ~]# docker pull centos:7
[root@localhost ~]# docker pull httpd
[root@localhost ~]# docker pull busybox
[root@localhost ~]# docker pull registry:2(这个是私有仓库的镜像哦)
二、开启私有仓库容器
[root@localhost ~]# docker run -itd -p 5000:5000 --restart always -v /opt/data/registry/:/var/lib/registry --name registry registry:2

解释一下参数:
-p 5000:5000:是将容器5000映射本机5000号端口
– restart always:表示容器退出时总重启容器
2、查看5000号端口是否开启

[root@localhost ~]# netstat -anput | grep 5000
tcp6       0      0 :::5000                 :::*                    LISTEN      3691/docker-proxy   
三、配置镜像仓库
  • 查看私有仓库
[root@localhost ~]# curl 192.168.111.55:5000/v2/_catalog(此处为主节点的IP地址)
{"repositories":[]}
  • 将仓库地址写入配置文件
    客户端 ip 也要指向镜像仓库,因此需在配置文件中写入镜像仓库地址
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service

  • 重载配置文件,重启docker
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# curl 192.168.111.55:5000/v2/_catalog
{"repositories":[]}
这里不需要启动容器就可以访问,主要依赖于之前创建容器时添加的--restart always
四、对镜像私有仓库进行的操作
  • 对镜像打标签
[root@localhost ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
busybox             latest              be5888e67be6        12 hours ago        1.22MB
httpd               latest              8326be82abe6        2 weeks ago         166MB
registry            2                   708bc6af7e5e        2 months ago        25.8MB
registry            latest              708bc6af7e5e        2 months ago        25.8MB
centos              7                   5e35e350aded        5 months ago        203MB

这是我现有的进行
下面我对busybox和httpd打标签上传

[root@localhost ~]# docker tag httpd:latest 192.168.111.55:5000/httpd
[root@localhost ~]# docker tag busybox:latest 192.168.111.55:5000/busybox
命名必须要是自己私有仓库的ip地址和端口哦
  • 上传本地镜像到私有仓库
[root@localhost ~]# docker push 192.168.111.55:5000/busybox
[root@localhost ~]# docker push 192.168.111.55:5000/httpd
[root@localhost ~]# curl 192.168.111.55:5000/v2/_catalog
{"repositories":["busybox","httpd"]}
查看已上传到私有仓库
  • 客户端从本地仓库下载镜像
    客户端需要修改docker配置文件添加服务端的IP和端口
    在这里插入图片描述
[root@localhost ~]# docker pull 192.168.111.55:5000/httpd
[root@localhost ~]# docker pull 192.168.111.55:5000/busybox
  • 下载成功
[root@localhost ~]# docker images
REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
192.168.111.55:5000/busybox   latest              be5888e67be6        15 hours ago        1.22MB
busybox                       latest              be5888e67be6        15 hours ago        1.22MB
busybox                       v1                  be5888e67be6        15 hours ago        1.22MB
192.168.111.55:5000/httpd     latest              8326be82abe6        2 weeks ago         166MB
httpd                         latest              8326be82abe6        2 weeks ago         166MB
httpd                         v1                  8326be82abe6        2 weeks ago         166MB
registry                      2                   708bc6af7e5e        2 months ago        25.8MB
registry                      latest              708bc6af7e5e        2 months ago        25.8MB
centos                        7                   5e35e350aded        5 months ago        203MB

你可能感兴趣的:(搭建docker私有仓库)