docker安装 搭建私库 删除私库镜像 打印私库镜像 的shell脚本
2019-01-16 15:42
537 查看
1.安装docker shell脚本
#!/bin/bash hub_docker="hub.dy.com" yum install -y epel-release docker sed -i "s#--selinux-enabled --log-driver=journald#--selinux-enabled=false --insecure-registry $hub_docker:5000 --log-driver=json-file --storage-driver=overlay2#g" /etc/sysconfig/docker # 开机自启 /usr/bin/systemctl daemon-reload /usr/bin/systemctl enable docker /usr/bin/systemctl start docker
2.私服的搭建 shell脚本
#!/bin/bash docker pull registry [ -d /home/registry ] || mkdir -p /home/registry cat <<EOF >/home/registry/config.yml version: 0.1 log: fields: service: registry storage: delete: enabled: true cache: blobdescriptor: inmemory filesystem: rootdirectory: /var/lib/registry http: addr: :5000 headers: X-Content-Type-Options: [nosniff] health: storagedriver: enabled: true interval: 10s threshold: 3 EOF docker run -itd -v /home/registry/:/var/lib/registry/ -v /home/registry/config.yml:/etc/docker/registry/config.yml -p 5000:5000 --restart=always --privileged=true --name registry registry
3.删除私库里面的镜像 shell脚本
#!/bin/bash docker_name="$1" docker_tag="$2" docker_hub_url="hub.dy.com:5000" docker_registry_container_id=`docker ps |grep registry |awk '{print $1}'` if [ "$docker_tag" = "" ]; then docker_tag="latest" fi #获取image的sha256 function get_docker_sha256(){ docker pull $docker_hub_url/$docker_name:$docker_tag > /dev/null 2>&1 #先下载下来 获取sha256 sha256=`docker inspect $docker_hub_url/$docker_name:$docker_tag | grep RepoDigests -A 5 | grep $docker_hub_url| grep sha256|awk -F '@' '{print $2}'|awk -F'"' '{print $1}'` #docker rmi $docker_hub_url/$docker_name:$docker_tag #然后删除本地镜像 是否删除 echo $sha256 } #删除镜像索引 function delete_images_index(){ sha256=`get_docker_sha256` echo $sha256 curl -I -X DELETE http://$docker_hub_url/v2/$docker_name/manifests/$sha256 } #删除镜像数据 function delete_images_data(){ docker exec -it $docker_registry_container_id registry garbage-collect /etc/docker/registry/config.yml } function main() { delete_images_index delete_images_data systemctl restart docker #重启docker 否则再次push 已经删除的镜像会出错 } main
4.打印私库里面的所有镜像 shell脚本
#!/bin/bash #本脚本可以打印私有镜像库中所有的镜像 #私有镜像库地址 HUB_URL=hub.dy.com:5000 #取得所有私有镜像库的所有镜像 IMAGESLIST=$(curl -s http://${HUB_URL}/v2/_catalog) #echo ${IMAGESLIST} #删除后2个字符 IMAGESLIST=${IMAGESLIST::-2} #删除前面17个字符 IMAGESLIST=${IMAGESLIST:17} #echo ${IMAGESLIST} #要将$a分割开,先存储旧的分隔符 OLD_IFS="$IFS" #设置分隔符 IFS="," #如下会自动分隔 arr=($IMAGESLIST) #遍历数组 for IMAGENAME in ${arr[@]} do #去掉引号 IMAGENAME=${IMAGENAME:1} IMAGENAME=${IMAGENAME::-1} #echo $IMAGENAME S1=$(curl -s http://${HUB_URL}/v2/${IMAGENAME}/tags/list) #取得[]中间的版本列表 S1=${S1#*[} S1=${S1%]*} #echo $S1 arr1=($S1) #遍历数组 for VAR in ${arr1[@]} do #去掉引号 VAR=${VAR:1} VAR=${VAR::-1} echo $HUB_URL/$IMAGENAME:$VAR done done #恢复原来的分隔符 IFS="$OLD_IFS"
相关文章推荐
- [容器]python搭建简易服务器+docker导入多个镜像shell脚本
- docker删除镜像和容器,安装,配置
- eclipse下搭建shell脚本编辑器--安装开发shell的eclipse插件shelled
- ubuntu16.04通过Jenkins+shell脚本打包docker镜像并推送到镜像
- centos7 Docker私有仓库搭建及删除镜像
- 搭建LAMP环境以及shell脚本搭建(yum安装)
- [置顶] 编写shell脚本实现自动化搭建安装LNMP平台全过程配置详解
- 用python脚本批量删除Docker镜像
- eclipse下搭建shell脚本编辑器--安装开发shell的eclipse插件shelled
- Jenkins 构建Docker镜像执行shell脚本用户权限问题
- shell脚本自动化安装docker_install.sh
- shell脚本一键安装nginx
- centos7系统下搭建docker本地镜像仓库
- shell脚本颜色打印输出
- Nginx+PHP(FastCGI)搭建高并发WEB服务器(自动安装脚本)第二版
- docker安装 镜像 容器 基础概念
- 用tarball实现liferay自动安装部署5-shell 脚本概述
- shell脚本一键安装mysql5.7.x
- 用SHELL脚本自动化安装Nagios服务器端和客户端的
- shell脚本操作oracle删除表空间、创建表空间、删除用户