名称 | 版本 |
---|---|
系统 | CentOS Linux release 7.6.1810 (Core) |
Docker version | 1.13.1 |
registry server ip | 192.168.199.120 |
docker client ip | 192.168.199.121 |
server 执行以下命令,创建私有仓库
#修改交互协议
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://i70c3eqq.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.199.120:5000"]
}
#重启docker服务
systemctl restart docker
#下载镜像
docker pull hub.c.163.com/library/registry:latest
docker tag hub.c.163.com/library/registry:latest registry
#启动容器
docker run -d --name=registry -p 5000:5000 --restart=always -v /myreg:/var/lib/registry registry
client : 192.168.199.121 执行推送镜像命令
注意:镜像名称严格安照 ip:端口/镜像名
#修改交互协议
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://i70c3eqq.mirror.aliyuncs.com"],
"insecure-registries": ["192.168.199.120:5000"]
}
#重启docker服务
systemctl restart docker
#查看构建的镜像
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 5eecbf8f6d43 58 seconds ago 193 MB
192.168.199.120:5000/centos v1 9f38484d220f 13 days ago 203 MB
docker.io/centos latest 9f38484d220f 13 days ago 202 MB
#执行推送命令(镜像严格按照registry格式命名)
docker push 192.168.199.120:5000/centos:v1
获取本地仓库192.168.199.120中存储的镜像
curl http://192.168.199.120:5000/v2/_catalog
{"repositories":["centos_push"]} #有一个叫 centos_push 镜像
curl http://192.168.199.120:5000/v2/centos_push/tags/list #查看centos_push 拥有的版本信息
{"name":"centos_push","tags":["latest","v1","v2","v3"]}
添加本地仓库为默认下载镜像地址
vim /etc/sysconfig/docker
#添加一行:
ADD_REGISTRY='--add-registry 192.168.199.120:5000'
#重启docker服务
systemctl restart docker
本地仓库删除镜像 192.168.199.120:5000/centos:v1
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/null
chmod a+x /usr/local/bin/delete_docker_registry_image
#本地挂载点为myreg
export REGISTRY_DATA_DIR=/myreg/docker/registry/v2
/usr/local/bin/delete_docker_registry_image -i centos:v1