registry私有仓库
下载docker-distribution软件包
yum install epel-release yum install docker-distribution
查看docker-distribution配置文件
[root@localhost registry]# vim /etc/docker-distribution/registry/config.yml version: 0.1 #版本 log: fields: service: registry #服务名称 storage: cache: layerinfo: inmemory filesystem: rootdirectory: /var/lib/registry #镜像目录 http: addr: :5000 #docker-distribution监听的端口
启动服务
[root@localhost registry]# systemctl restart docker-distribution
查看5000端口是否启动
[root@localhost registry]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:111 *:* LISTEN 0 5 192.168.122.1:53 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::5000 :::* LISTEN 0 128 :::111 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::*
查看本地镜像
[root@localhost registry]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE myos latest c14c79e9da64 4 weeks ago 466MB centos latest 9f38484d220f 6 months ago 202MB
现在我们把centos这个镜像打上标签并且推送到registry中
[root@localhost registry]# docker tag centos 192.168.254.11:5000/centos:latest
[root@localhost registry]# docker push 192.168.254.11:5000/centos The push refers to repository [192.168.254.11:5000/centos] d69483a6face: Pushed latest: digest: sha256:ca58fe458b8d94bc6e3072f1cfbd334855858e05e1fd633aa07cf7f82b048e66 size: 529
查看registry服务器
[root@localhost repositories]# ls -ltr /var/lib/registry/docker/registry/v2/repositories total 0 drwxr-xr-x. 5 root root 55 Sep 13 10:28 centos drwxr-xr-x. 5 root root 55 Sep 13 10:48 mysql
镜像已经上传上来了,OK
客户端
如果客户端向拉取镜像需要在客户端编辑/etc/docker/daemon.json文件添加
[root@slave yum.repos.d]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://l10nt4hq.mirror.aliyuncs.com"], "insecure-registries":["192.168.254.17:5000"]#写入register服务器的ip和端口号 }
然后在拉取镜像
[root@slave yum.repos.d]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE [root@slave yum.repos.d]# docker pull 192.168.254.17:5000/busybox:latest latest: Pulling from busybox bdbbaa22dec6: Pull complete Digest: sha256:edafc0a0fb057813850d1ba44014914ca02d671ae247107ca70c94db686e7de6 Status: Downloaded newer image for 192.168.254.17:5000/busybox:latest 192.168.254.17:5000/busybox:latest [root@slave yum.repos.d]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE 192.168.254.17:5000/busybox latest 6d5fcfe5ff17 6 weeks ago 1.22MB
harbor私有仓库
下载harbor包
wget https://storage.googleapis.com/harbor-releases/release-1.4.0/harbor-offline-installer-v1.4.0.tgz
解压包并进入目录
tar -zxvf harbor-offline-installer-v1.4.0.tgz -C /usr/local/ cd /usr/local/harbor
编辑配置文件
vim harbor.cfg hostname = 192.168.254.13 #对外访问地址 ui_url_protocol = http #访问方式 max_job_workers = 3 #最大处理进程数 customize_crt = on #是否要启动自定义证书,如果ui_url_protocol = http不生效,如果是https才会生效
harbor_admin_password = Harbor12345 #admin用户的密码
执行文件
[root@master harbor]# ./install.sh note:容器名字不能有registry这个名字,否则脚本执行失败
浏览器访问http://server_ip
创建项目
创建仓库
修改访问地址
[root@master harbor]# vim /etc/docker/daemon.json { "registry-mirrors": ["https://l10nt4hq.mirror.aliyuncs.com"], "insecure-registries":["192.168.254.13"] }
重启docker服务
[root@master harbor]# service docker restart
Redirecting to /bin/systemctl restart docker.service
在linux下登录harbor
查看现有的镜像
[root@master harbor]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry.aliyuncs.com/google_containers/kube-proxy v1.15.3 232b5c793146 3 weeks ago 82.4 MB registry.aliyuncs.com/google_containers/kube-apiserver v1.15.3 5eb2d3fc7a44 3 weeks ago 207 MB registry.aliyuncs.com/google_containers/kube-scheduler v1.15.3 703f9c69a5d5 3 weeks ago 81.1 MB registry.aliyuncs.com/google_containers/kube-controller-manager v1.15.3 e77c31de5547 3 weeks ago 159 MB docker.io/mariadb latest 99c1098d5884 4 weeks ago 355 MB docker.io/mysql latest 62a9f311b99c 4 weeks ago 445 MB quay.io/coreos/flannel v0.11.0-amd64 ff281650a721 7 months ago 52.6 MB registry.aliyuncs.com/google_containers/coredns 1.3.1 eb516548c180 8 months ago 40.3 MB registry.aliyuncs.com/google_containers/etcd 3.3.10 2c4adeb21b4f 9 months ago 258 MB vmware/clair-photon v2.0.1-v1.4.0 a1df3526fe43 19 months ago 300 MB vmware/notary-server-photon v0.5.1-v1.4.0 3edfddb8ece2 19 months ago 211 MB vmware/notary-signer-photon v0.5.1-v1.4.0 cc70a05cdb6a 19 months ago 209 MB vmware/registry-photon v2.6.2-v1.4.0 8920f621ddd1 19 months ago 198 MB vmware/nginx-photon v1.4.0 20c8a01ac6ab 19 months ago 135 MB vmware/harbor-log v1.4.0 9e818c7a27ab 19 months ago 200 MB vmware/harbor-jobservice v1.4.0 29c14d91b043 19 months ago 191 MB vmware/harbor-ui v1.4.0 6cb4318eda6a 19 months ago 210 MB vmware/harbor-adminserver v1.4.0 8145970fa013 19 months ago 182 MB vmware/harbor-db v1.4.0 c38da34727f0 19 months ago 521 MB vmware/mariadb-photon v1.4.0 8457013cf6e3 19 months ago 521 MB vmware/postgresql-photon v1.4.0 59aa61520094 19 months ago 221 MB vmware/harbor-db-migrator 1.4 7a4d871b612e 20 months ago 1.15 GB vmware/photon 1.0 9b411d78ad9e 20 months ago 130 MB registry.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 21 months ago 742 kB
给要上传的包打标签
[root@master harbor]# docker tag docker.io/mysql:latest 192.168.254.13/databases/mysql:v1
上传镜像
[root@master harbor]# docker push 192.168.254.13/databases/mysql:v1 The push refers to a repository [192.168.254.13/databases/mysql] 647229410363: Pushed 5b96d5043191: Pushed 79a46f1eb9d0: Pushed bdebd19e878f: Pushed 995fa4bb8afe: Pushed bb1ef34119b2: Pushed 65430c57aee2: Pushed 1dd5f3e365cf: Pushed 7f33ce1066af: Pushed 9f77b78f01a7: Pushed f5741d086b76: Pushed 8fa655db5360: Pushed v1: digest: sha256:f0392b61ae096aef93b25f4b88206d774d2de1a7e43a7780a59a0c319c540b79 size: 2828
浏览器查看harbor
已经上传成功,ok
补充
开启或关闭harbor:
docker-compose up -d
docker-compose stop