1.Docker私有仓库registry搭建
1.下载registry镜像
命令:
docker pull registry
[root@centos79 ~]# docker search registry
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
registry Distribution implementation for storing and … 3926 [OK]
okteto/registry 0
distribution/registry WARNING: NOT the registry official image!!! … 57 [OK]
okteto/registry-configurator 0
hephy/registry-proxy 0
okteto/registry-auth 0
kope/registry 0
hephy/registry Docker image registry for the Hephy - Fork o… 0
silintl/registry-proxy A reverse proxy for the Docker Registry 2.0 1 [OK]
drud/registry 0
hephy/registry-token-refresher 0
runcitadel/registry-photon 0
google/docker-registry Docker Registry w/ Google Cloud Storage driv… 55
docker/dtr Docker Trusted Registry 15
reseaucerta/registry 0
opensuse/registry Docker registry based on openSUSE. 0 [OK]
snyk/container-registry-agent Container registry agent allows securely con… 2
bitnami/schema-registry Bitnami Docker Image for Schema Registry 0
docker/migrator Tool to migrate Docker images from a v1 regi… 8 [OK]
apache/nifi-registry Unofficial convenience binaries for Apache N… 42
docker/trusted-registry-index Search Index for Docker Trusted Registry 0
verdaccio/verdaccio Verdaccio Official Docker Image: A lightweig… 187 [OK]
joxit/docker-registry-ui Docker registry v2 web User Interface 134 [OK]
opensuse/portus Authorization service and frontend for Docke… 93 [OK]
jhipster/jhipster-registry JHipster Registry, based on Netflix Eureka a… 59 [OK]
[root@centos79 ~]# docker pull registry
Using default tag: latest
latest: Pulling from library/registry
79e9f2f55bf5: Pull complete
0d96da54f60b: Pull complete
5b27040df4a2: Pull complete
e2ead8259a04: Pull complete
3790aef225b9: Pull complete
Digest: sha256:169211e20e2f2d5d115674681eb79d21a217b296b43374b8e39f97fcf866b375
Status: Downloaded newer image for registry:latest
docker.io/library/registry:latest
[root@centos79 ~]# docker images | grep registry
registry latest b8604a3fe854 2 years ago 26.2MB
[root@centos79 ~]#
2.启动docker registry
命令:
mkdir -p /data/registry
docker run -itd -p 5000:5000 -v /data/registry:/var/lib/registry --name my_registry registry:latest
[root@centos79 ~]# mkdir -p /data/registry
[root@centos79 ~]# docker run -itd -p 5000:5000 -v /data/registry:/var/lib/registry --name my_registry registry:latest
010c6b9f39353a20f17a271ae3cd1efb07ad922515da4a818abd3709cce3c713
[root@centos79 ~]#
3.查看运行的docker容器
命令:
docker ps | grep my_registry
netstat -antulp | grep 5000
[root@centos79 ~]# docker ps | grep my_registry
010c6b9f3935 registry:latest "/entrypoint.sh /etc…" 18 seconds ago Up 16 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp my_registry
[root@centos79 ~]# netstat -antulp | grep 5000
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 5313/docker-proxy
tcp 0 0 172.20.10.12:59834 172.20.10.12:5000 TIME_WAIT -
tcp6 0 0 :::5000 :::* LISTEN 5319/docker-proxy
[root@centos79 ~]#
4.本地配置docker registry,并保存
命令:
vim /etc/docker/daemon.json
添加前:
[root@centos79 ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://ykjpg821.mirror.aliyuncs.com"]
}
[root@centos79 ~]#
添加后:
[root@centos79 ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://ykjpg821.mirror.aliyuncs.com"],
"insecure-registries": ["172.20.10.12:5000"]
}
[root@centos79 ~]#
5.重启docker
命令:
systemctl reload
systemctl stop docker
systemctl start docker
systemctl status docker
[root@centos79 ~]# systemctl daemon-reload
[root@centos79 ~]# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
[root@centos79 ~]# systemctl start docker
[root@centos79 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2023-12-11 14:49:33 CST; 4s ago
Docs: https://docs.docker.com
Main PID: 4363 (dockerd)
Tasks: 115
Memory: 125.6M
CGroup: /system.slice/docker.service
├─4363 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
├─4532 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9300 -container-ip 172.18.0.2 -container-port 9300
├─4537 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9300 -container-ip 172.18.0.2 -container-port 9300
├─4554 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9601 -container-ip 172.18.0.3 -container-port 9600
├─4560 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9601 -container-ip 172.18.0.3 -container-port 9600
├─4574 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9600 -container-ip 172.18.0.4 -container-port 9600
├─4579 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9600 -container-ip 172.18.0.4 -container-port 9600
├─4594 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 9200 -container-ip 172.18.0.2 -container-port 9200
├─4600 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 9200 -container-ip 172.18.0.2 -container-port 9200
├─4614 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5601 -container-ip 172.18.0.5 -container-port 5601
├─4622 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5601 -container-ip 172.18.0.5 -container-port 5601
├─4660 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5045 -container-ip 172.18.0.3 -container-port 5044
├─4666 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5045 -container-ip 172.18.0.3 -container-port 5044
├─4714 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5044 -container-ip 172.18.0.4 -container-port 5044
└─4730 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5044 -container-ip 172.18.0.4 -container-port 5044
12月 11 14:49:33 centos79 systemd[1]: Starting Docker Application Container Engine...
12月 11 14:49:33 centos79 dockerd[4363]: time="2023-12-11T14:49:33.063840023+08:00" level=info msg="Starting up"
12月 11 14:49:33 centos79 dockerd[4363]: time="2023-12-11T14:49:33.079199476+08:00" level=info msg="[graphdriver] using pri...erlay2"
12月 11 14:49:33 centos79 dockerd[4363]: time="2023-12-11T14:49:33.086861746+08:00" level=info msg="Loading containers: start."
12月 11 14:49:33 centos79 dockerd[4363]: time="2023-12-11T14:49:33.189189056+08:00" level=info msg="Default bridge (docker0...ddress"
12月 11 14:49:33 centos79 dockerd[4363]: time="2023-12-11T14:49:33.694601228+08:00" level=info msg="Loading containers: done."
12月 11 14:49:33 centos79 dockerd[4363]: time="2023-12-11T14:49:33.708625705+08:00" level=info msg="Docker daemon" commit=3...=24.0.7
12月 11 14:49:33 centos79 dockerd[4363]: time="2023-12-11T14:49:33.708665813+08:00" level=info msg="Daemon has completed in...zation"
12月 11 14:49:33 centos79 dockerd[4363]: time="2023-12-11T14:49:33.868251008+08:00" level=info msg="API listen on /run/docker.sock"
12月 11 14:49:33 centos79 systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.
[root@centos79 ~]#
6.启动docker registry
命令:
docker ps -a | grep my_registry
docker start my_registry
docker ps -a | grep my_registry
[root@centos79 ~]# docker ps -a | grep my_registry
010c6b9f3935 registry:latest "/entrypoint.sh /etc…" 26 minutes ago Exited (2) 15 minutes ago my_registry
[root@centos79 ~]#
[root@centos79 ~]# docker start my_registry
my_registry
[root@centos79 ~]# docker ps -a | grep my_registry
010c6b9f3935 registry:latest "/entrypoint.sh /etc…" 26 minutes ago Up 2 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp my_registry
[root@centos79 ~]#
7.上传镜像进行验证
命令:
docker images | grep nginx
docker tag nginx:latest 172.20.10.12:5000/nginx:1.0
docker images | grep nginx
docker push 172.20.10.12:5000/nginx:1.0
[root@centos79 ~]# docker images | grep nginx
nginx latest 605c77e624dd 23 months ago 141MB
[root@centos79 ~]# docker tag nginx:latest 172.20.10.12:5000/nginx:1.0
[root@centos79 ~]# docker images | grep nginx
172.20.10.12:5000/nginx 1.0 605c77e624dd 23 months ago 141MB
nginx latest 605c77e624dd 23 months ago 141MB
[root@centos79 ~]# docker push 172.20.10.12:5000/nginx:1.0
The push refers to repository [172.20.10.12:5000/nginx]
d874fd2bc83b: Pushed
32ce5f6a5106: Pushed
f1db227348d0: Pushed
b8d6e692a25e: Pushed
e379e8aedd4d: Pushed
2edcec3590a4: Pushed
1.0: digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3 size: 1570
[root@centos79 ~]#
8.检查本地私有仓库
命令:
curl -XGET http://172.20.10.12:5000/v2/_catalog
curl -XGET http://172.20.10.12:5000/v2/nginx/tags/list
[root@centos79 ~]# curl -XGET http://172.20.10.12:5000/v2/_catalog
{"repositories":["nginx"]}
[root@centos79 ~]#
[root@centos79 ~]# curl -XGET http://172.20.10.12:5000/v2/nginx/tags/list
{"name":"nginx","tags":["1.0"]}
[root@centos79 ~]#
至此,docker registry私有仓库搭建完毕!