因爲部分圖片的問題,附上有道雲筆記中的連接:http://note.youdao.com/noteshare?id=973cd2cd200dca3769bc9cd2a6b9b746&sub=71498BEACB1F42DE99EDF4B403145BC7node
Docker私有倉庫的安裝
1.Registry
官方的Docker hub是一個用於管理公共鏡像的好地方,咱們能夠在上面找到咱們想要的鏡像,也能夠把咱們本身的鏡像推送上去。可是,有時候,咱們的使用場景須要咱們擁有一個私有的鏡像倉庫用於管理咱們本身的鏡像。這個能夠經過開源軟件Registry來達成目的。python
Registry在github上有兩份代碼:老代碼庫和新代碼庫。老代碼是採用python編寫的,存在pull和push的性能問題,出到0.9.1版本以後就標誌爲deprecated,再也不繼續開發。從2.0版本開始就到在新代碼庫進行開發,新代碼庫是採用go語言編寫,修改了鏡像id的生成算法、registry上鏡像的保存結構,大大優化了pull和push鏡像的效率。git
官方在Docker hub上提供了registry的鏡像(詳情),咱們能夠直接使用該registry鏡像來構建一個容器,搭建咱們本身的私有倉庫服務。Tag爲latest的registry鏡像是0.9.1版本的,咱們直接採用2.1.1版本。github
2.Registry部署
2.1 獲取registry鏡像
docker pull registry:2.1.1
2.2 啓動registry鏡像
[root@node1 bin]# docker run -d -v /opt/data/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry:2.1.1
默認狀況下,registry會將上傳的鏡像保存在容器的/var/lib/registry,咱們將主機的/opt/data/registry目錄掛載到該目錄,便可實現將鏡像保存到主機的/opt/data/registry目錄了算法
2.3查看啓動狀況
2.4 啓動register服務以後,經過瀏覽器訪問:192.168.44.201:5000/v2
3.上傳image到私有倉庫
3.1 打tag(centos:7.5.1804是本地已經有的image)
docker tag centos:7.5.1804 192.168.44.201:5000/centos:7.5.1804
3.2 push
docker push 192.168.44.201:5000/centos:7.5.1804
由於Docker從1.3.X以後,與docker registry交互默認使用的是https,然而此處搭建的私有倉庫只提供http服務,因此當與私有倉庫交互時就會報下面的錯誤: docker
爲了解決這個問題須要在啓動docker server時增長啓動參數爲默認使用http訪問。修改docker啓動配置文件:vim
[root@node1 bin]# vim /usr/lib/systemd/system/docker.service [Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com After=network-online.target firewalld.service Wants=network-online.target [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker #ExecStart=/usr/bin/dockerd --insecure-registry 192.168.44.201:5000 ##加上這一句 ExecStart=/usr/bin/dockerd ExecReload=/bin/kill -s HUP $MAINPID # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Uncomment TasksMax if your systemd version supports it. # Only systemd 226 and above support this version. #TasksMax=infinity TimeoutStartSec=0 # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s [Install] WantedBy=multi-user.target
以後重啓dockercentos
systemctl daemon-reload systemctl start docker
以後再從新push,成功 瀏覽器
3.3 瀏覽器查看
4.查看相關私有倉庫的信息
4.1 私有倉庫的images
[root@node1 bin]# curl http://192.168.44.201:5000/v2/_catalog {"repositories":["centos"]} [root@node1 bin]#
4.2 查看對應image的tag信息
[root@node1 bin]# curl http://192.168.44.201:5000/v2/centos/tags/list {"name":"centos","tags":["7.5.1804","7.5.1804.2"]} [root@node1 bin]#
5.刪除私有倉庫的image
5.1 下載資源
curl https://raw.githubusercontent.com/burnettk/delete-docker-registry-image/master/delete_docker_registry_image.py | sudo tee /usr/local/bin/delete_docker_registry_image >/dev/null
chmod +x /usr/local/bin/delete_docker_registry_image
5.2 設置相關環境變量
[root@node1 bin]# export REGISTRY_DATA_DIR='/opt/data/registry/docker/registry/v2/'
由於delete_docker_registry_image中須要用到REFISTRY_DATA_DIR這個環境變量curl
5.3 刪除image
[root@node1 bin]# delete_docker_registry_image --image centos:7.5.1804.2
刪除成功!!!