CentOS7下快速搭建Docker私有庫

1. 安裝Docker

yum -y install docker

2. 啓動Docker服務

systemctl enable docker
systemctl start docker

3. 啓動Docker私有庫

mkdir /home/docker_repo
cd /home/docker_repo
docker run -d -p 5000:5000 --name registry --restart=always --privileged=true -v $PWD:/var/lib/registry registry:2

4. 提交Docker鏡像

docker tag docker.io/hello-world:latest 192.168.1.75:5000/hello-world:latest
docker push 192.168.1.75:5000/hello-world

如果push遇到問題,編輯/usr/lib/systemd/system/docker.service,在ExecStart=之後追加一行參數:

--insecure-registry=192.168.1.75:5000 \

然後重啓Docker服務:

systemctl daemon-reload
systemctl restart docker

5. Docker私有庫HTTP API

測試庫內已有centos和Docker官方的hello-world鏡像

  • 查看當前庫列表
    http://192.168.1.75:5000/v2/_catalog

    返回:

    {
    "repositories": [
        "centos",
        "hello-world"
    ]
    }
  • 查看某個庫標籤列表
    http://192.168.1.75:5000/v2/hello-world/tags/list

    返回:

    {
    "name": "hello-world",
    "tags": [
        "latest"
    ]
    }

    注: 需要把192.168.1.75替換成你的Docker私有庫所在服務器IP

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章