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

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