docker镜像私服registry的安装
安装docker的registry私服和registry-frontend (UI)
一、registry服务器端
mkdir registry
cd registry
docker pull registry #拉取镜像
vi docker-compose.yml ,内容如下
version: '3'
services:
registry:
image: registry
restart: always
container_name: registry
ports:
- 5000:5000
volumes:
- /opt/registry_data:/var/lib/registry
- ./config.yml:/etc/docker/registry/config.yml
frontend:
image: konradkleine/docker-registry-frontend:v2
container_name: registry-frontend
ports:
- 80:80
volumes:
- ./certs/frontend.crt:/etc/apache2/server.crt:ro
- ./certs/frontend.key:/etc/apache2/server.key:ro
environment:
- ENV_DOCKER_REGISTRY_HOST=192.168.11.12
- ENV_DOCKER_REGISTRY_PORT=5000
depends_on:
- registry
mkdir -p /opt/registry_data #创建registry数据存储目录
vi config.yml #registry私服配置信息,内容如下,
version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
delete:
enabled: true
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
注意启用delete 功能。
docker-compose up -d #启动服务
#验证registry服务是否可访问
curl http://192.168.11.12:5000/v2/
curl http://192.168.11.12:5000/v2/_catalog
二、docker客户端配置
vi /etc/docker/daemon.json 如下
{
"registry-mirrors": ["https://4piak27r.mirror.aliyuncs.com"],
"insecure-registries": [ "192.168.11.12:5000"]
}
新增 "insecure-registries": [ "192.168.11.12:5000"]
#重启docker守护进程
systemctl daemon-reload
systemctl restart docker
docker info #查看私有registry
Insecure Registries:
192.168.11.12:5000
127.0.0.0/8
#推送和拉取镜像测试(使用私服)
docker tag node:10-alpine 192.168.11.12:5000/jellyflu/node:10-alpine
docker push 192.168.11.12:5000/jellyflu/node:10-alpine
docker rmi 192.168.11.12:5000/jellyflu/node:10-alpine
docker pull 192.168.11.12:5000/jellyflu/node:10-alpine
使用浏览器访问后台:
(
附:
#删除私服中的镜像
curl --header "Accept: application/vnd.docker.distribution.manifest.v2+json" -I \
-X HEAD http://192.168.11.12:5000/v2/jellyflu/busybox/manifests/latest
#得到镜像的sha256码后,再使用 curl -x delete 进行删除
curl -I -X DELETE 192.168.11.12:5000/v2/jellyflu/busybox/manifests/sha256:24fd20af232ca4ab5efbf1aeae7510252e2b60b15e9a78947467340607cd2ea2
)
三、registry中用户空间、仓库、镜像的删除
在registry服务器端安装:
curl https://raw.githubusercontent.com/burnettk/delete-docker-registry-image/master/delete_docker_registry_image.py | sudo tee /usr/local/bin/delete_docker_registry_image >/dev/nul
chmod a+x /usr/local/bin/delete_docker_registry_image #赋予可执行权限
Actually delete a repo (remember to shut down your registry first):
delete_docker_registry_image --image testrepo/awesomeimage
Delete one tag from a repo:
delete_docker_registry_image --image testrepo/awesomeimage:supertag
例如:
delete_docker_registry_image --image python:3.7-alpine (删除指定镜像的指定tag,无用户空间)
delete_docker_registry_image --image python (删除指定镜像,无用户空间)
delete_docker_registry_image --image jellyflu/busybox (删除某个用户空间下的指定仓库)
delete_docker_registry_image --image jellyflu (删除整个用户空间)
非常简单,比我们手动用curl -x delete ... 的删除方式要好用得多了。
下一篇: Java分享笔记:关于Java反射机制