1. 拉取镜像
docker pull registry
2.启动容器
docker run -d -v /docker_registry:/var/lib/registry -p 5000:5000 --name registry --restart=always registry:latest
3.查看容器
docker ps -a
4.通过浏览器访问查看私有仓库镜像
http://127.0.0.1:5000/v2/_catalog
5.编辑私有仓库上传地址
[root@cloud ~]# hostname
aa.bb.cc
[root@cloud ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://vy58b67c.mirror.aliyuncs.com"],
"insecure-registries":["aa.bb.cc:5000"]
}
6.重启docker服务,重启registry服务
systemctl restart docker
docker restart registry --启动命令添加自启动了不用执行
1.验证上传镜像到私有仓库
拉取镜像
docker pull hello-world
重命名镜像
docker tag hello-world:latest aa.bb.cc:5000/test:1.0.1
上传到私有仓库
[root@cloud ~]# docker push aa.bb.cc:5000/test:1.0.1
The push refers to repository [aa.bb.cc:5000/test]
9c27e219663c: Pushed
1.0.1: digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042 size: 525
4.查看私有仓库镜像
curl http://aa.bb.cc:5000/v2/_catalog
{"repositories":["test"]}
这样就表示成功了
验证从私有仓库拉取镜像
删除原有镜像
docker image rm -f aa.bb.cc:5000/test:1.0.1
Untagged: aa.bb.cc:5000/test:1.0.1
Untagged: aa.bb.cc:5000/test@sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b
Deleted: sha256:9c27e219663c25e0f28493790cc0b88bc973ba3b1686355f221c38a36978ac63
拉取镜像
docker pull aa.bb.cc:5000/test:1.0.1
1.0.1: Pulling from test
0e03bdcc26d7: Pull complete
Digest: sha256:90659bf80b44ce6be8234e6ff90a1ac34acbeb826903b02cfa0da11c82cbc042
Status: Downloaded newer image for aa.bb.cc:5000/test:1.0.1
aa.bb.cc:5000/test:1.0.1
查看是否拉取成功
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry latest 678dfa38fcfa 3 weeks ago 26.2MB
aa.bb.cc:5000/test 1.0.1 bf756fb1ae65 12 months ago 13.3kB
到此私有仓库配置成功,上传、拉取镜像成功。
涉及到隐私,我把个人电脑名、域名做了修改 aa.bb.cc ,实际中可以随便修改域名。配置好hosts hostname就可以了,外网也可以访问私有仓库的话,要做好5000端口的映射就可以了。