运行自己的docker registry私有仓库
1、拉取registry镜像
[liu@liuzexia root]$ sudo docker pull registry
Using default tag: latest
latest: Pulling from library/registry
cbdbe7a5bc2a: Pull complete
47112e65547d: Pull complete
46bcb632e506: Pull complete
c1cc712bcecd: Pull complete
3db6272dcbfa: Pull complete
Digest: sha256:8be26f81ffea54106bae012c6f349df70f4d5e7e2ec01b143c46e2c03b9e551d
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
2、配置daemon.json 文件,添加以下内容
"insecure-registries":["47.111.238.173:5000"] ///47.111.238.173这个IP是需要当镜像服务器的IP
[liu@liuzexia root]$ sudo cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://8icosyye.mirror.aliyuncs.com"],
"insecure-registries":["47.111.238.173:5000"]
}
3、然后重启docker
[liu@liuzexia root]$ sudo systemctl daemon-reload
[liu@liuzexia root]$ sudo systemctl restart docker
4、启动registry容器
[liu@liuzexia root]$ sudo docker run -d --name registry -p 5000:5000 --restart=always -v /opt/registry/:/var/lib/registry/ registry
3cc9dd9bac459434358f853824293971f41aa8b6256d82f58aa3275803d38ceb
[liu@liuzexia root]$
上传到私有镜像默认是放在/var/lib/registry/,为了防止删除registry,上传的镜像也被删除,所以启用一个volume,将上传的镜像持久化保存在我们物理机上,这里保存位置是/opt/registry/
5、测试是否启动容器
[liu@liuzexia root]$ sudo curl http://47.111.238.173:5000/v2/_catalog
{"repositories":[]}
[liu@liuzexia root]$
如果返回{"repositories":[]},代表启动成功了
6、给jamtur01/static_web镜像打上标签为my_jamtur01/static_web(自己命名)
[liu@liuzexia root]$ sudo docker images jamtur01/static_web
REPOSITORY TAG IMAGE ID CREATED SIZE
jamtur01/static_web latest 7c3b35d31608 4 years ago 220MB
[liu@liuzexia root]$ sudo docker tag 7c3b35d31608 47.111.238.173:5000/my_jamtur01/static_web
[liu@liuzexia root]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 4e2eef94cd6b 3 weeks ago 73.9MB
centos latest 0d120b6ccaa8 4 weeks ago 215MB
registry latest 2d4f4b5309b1 2 months ago 26.2MB
ubuntu 14.04 6e4f1fe62ff1 8 months ago 197MB
jamtur01/static_web latest 7c3b35d31608 4 years ago 220MB
47.111.238.173:5000/my_jamtur01/static_web latest 7c3b35d31608 4 years ago 220MB
[liu@liuzexia root]$
7、将my_jamtur01/static_web镜像推送到新的自己阿里云仓库registry
[liu@liuzexia root]$ sudo docker push 47.111.238.173:5000/my_jamtur01/static_web
[sudo] password for liu:
The push refers to repository [47.111.238.173:5000/my_jamtur01/static_web]
85093ab5bcaf: Pushed
849f4126a8d0: Pushed
9a39129ae0ac: Pushed
98305c1a8f5e: Pushed
0185b3091e8e: Pushed
ea9f151abb7e: Pushed
latest: digest: sha256:979fea6fefb54f70ffd7940caf6f53153f0f432adc12eaf0f1314db0bff380d2 size: 1569
[liu@liuzexia root]$
8、测试,在别的机子上拉取该镜像
[root@managers report]# docker pull 47.111.238.173:5000/my_jamtur01/static_web
Using default tag: latest
latest: Pulling from my_jamtur01/static_web
4755ec6c1fe3: Pull complete
41449e5974ae: Pull complete
a7e22d1f1b7c: Pull complete
4f063bb23421: Pull complete
170ad41ad0e2: Pull complete
f2303bdbbb59: Pull complete
Digest: sha256:979fea6fefb54f70ffd7940caf6f53153f0f432adc12eaf0f1314db0bff380d2
Status: Downloaded newer image for 47.111.238.173:5000/my_jamtur01/static_web:latest
47.111.238.173:5000/my_jamtur01/static_web:latest
[root@managers report]# docker imgages
docker: 'imgages' is not a docker command.
See 'docker --help'
[root@managers report]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
openjdk 8u265-jdk db530b5a3ccf 2 days ago 511MB
mysql 5.6 44241dbd4d38 2 days ago 302MB
nginx 1.19.1 08393e824c32 5 weeks ago 132MB
tomcat 8.5.15-jre8 b8dfe9ade316 3 years ago 334MB
47.111.238.173:5000/my_jamtur01/static_web latest 7c3b35d31608 4 years ago 220MB
[root@managers report]#