1. 程式人生 > >docker 、rancher搭建

docker 、rancher搭建

docker rancher registry

一、安裝前準備:

  1. 配置本地yum源

    1).mount -t iso9660 -o loop /dev/cdrom /media/centos

2).vi /etc/yum.repo.d/Centos_localsource.repo

[CentOS7-Localsource]
name=CentOS7
baseurl=file:///media/centos
enabled=1
gpgcheck=0

2.配置網絡yum源

下載163網易的yum源:
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
中科大的yum源:
wget http://centos.ustc.edu.cn/CentOS-Base.repo
sohu的yum源
wget http://mirrors.sohu.com/help/CentOS-Base-sohu.repo

3.yum clean all

yum makecache

yum isntall vim net-tools #(支持ifconfig)

(setenforce 0 && systemctl stop firewalld)


二、安裝docker和rancher

  1. 下載docker的rpm包(https://download.docker.com/linux/centos/7/x86_64/stable/Packages/)

    docker-ce-17.06.0.ce-1.el7.centos.x86_64.rpm

  2. 安裝docker

    yum install docker-ce-17.06.0.ce-1.el7.centos.x86_64.rpm

  3. 配置docker加速器

    vi /etc/docker/daemon.json

{"registry-mirrors": ["
或 
{"registry-mirrors": ["https://registry.docker-cn.com"]}

4.systemctl start docker

5.docker pull rancher/server

6.啟動rancher server

docker run -d -v /data1/mysql:/var/lib/mysql --name=rancher-server --restart=unless-stopped -p 7070:8080 rancher/server

7.rancher頁面配置及rancher-agent安裝見http://blog.chinaunix.net/uid-29757900-id-5676591.html


三、安裝registry

  1. docker pull registry

  2. 運行registry容器

docker run -d --restart=always -p 5000:5000 --name repo -v /var/lib/registry:/var/lib/registry  registry

3.修改/etc/docker/daemon.json添加"insecure-registries":["registry:5000"](參考:http://www.cnblogs.com/lin1/p/6207348.html)

{"registry-mirrors": ["https://registry.docker-cn.com"],"insecure-registries":["192.168.206.134:5000"] }

4.重啟docker

systemctl restart docker

5.將公有倉庫下載docker包上傳到私有倉庫(http://www.cnblogs.com/fengzheng/p/5168951.html)

#下載mysql鏡像
docker pull mysql       
#重新標記一個本地鏡像為私有倉庫的版本,這裏將本地的mysql latest標記為192.168.206.134:5000/mysql:yang
docker tag mysql:latest 192.168.206.134:5000/mysql:yang
#將本地鏡像推送到本地倉庫中
docker push 192.168.206.134:5000/mysql:yang
#查看本地倉庫中的鏡像列表
[[email protected] yum.repos.d]# curl http://localhost:5000/v2/mysql/tags/list
{"name":"mysql","tags":["yang"]}
#拉取本地倉庫中的鏡像
docker pull localhost:5000/mysql:yang

6.私有倉庫 Registry中的鏡像管理

#檢查registry上的鏡像
for i in `curl -s 127.0.0.1:5000/v2/_catalog | sed‘s/repositories// ; s/[\[\"\:\{\}]*//g ; s/,/ /g ; s/]//g‘` ; do curl -s 127.0.0.1:5000/v2/$i/tags/list|sed‘s/[\{\}\"]//g; s/name://g; s/,tags:/\t/g‘ ; done
#刪除私有 registry 中的鏡像(參考:http://www.cnblogs.com/wjoyxt/p/5855405.html)
1.修改配置/etc/docker/registry/config.yml
2.使用 API GET /v2/<鏡像名>/manifests/<tag> 來取得要刪除的鏡像:Tag所對應的 digest
比如,要刪除 mysql:yang 鏡像,那麽取得 digest 的命令是:
curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I -X HEAD http://192.168.206.134:5000/v2/mysql/manifests/yang
 3.然後調用 API DELETE /v2/<鏡像名>/manifests/<digest> 來刪除鏡像。比如:
 [[email protected] yum.repos.d]# curl -X DELETE "http://192.168.206.134:5000/v2/mysql/manifests/sha256:afd334d5f3b4c31155a09110ad7f4728e8b5c8bdf8bca711aed61cf8247dfdec"

 {"errors":[{"code":"UNSUPPORTED","message":"The operation is unsupported."}]}
----配置文件已改,但是沒刪除成功。問題待解----


docker 、rancher搭建