After completing the experiment on my own computer, I hope to restore the whole environment in the development environment, and it is an Intranet environment, so I need to pack all the images in the process of building gitLab. Restore on the Intranet

Currently, Gitlab + Gitlab-Runner is used. Container Registry uses gitlab’s own container registry, so harbor is not used to save space.

Mirror local Backup

#! /bin/bashIMAGES_LIST=($(docker images | sed '1d' | awk '{print $1}')) IMAGES_NM_LIST=($(docker images | sed '1d' | awk '{print $1"-"$2}'| awk -F/ '{print $NF}')) IMAGES_NUM=${#IMAGES_LIST[*]} for((i=0; i<$IMAGES_NUM; i++)) do docker save "${IMAGES_LIST[$i]}" -o "${IMAGES_NM_LIST[$i]}".tar.gz doneCopy the code

The for loop uses docker Save to save the image to tar, mainly through sed and awk tools

Restore to local

cd $DIR/images_file
for image_name in $(ls ./)
do
  docker load < ${image_name}
done
Copy the code

The entire package images_file is recycled locally using docker load

Upload free Container Registry in batches


#! /bin/bashReadonly new_repo = 192.168.247.191:5005 / test for image in $(docker images - the format '{{. Repository}}, {{. Tag}} "); do name=${image##*/} new_img=${new_repo}/${name} echo "Processing ${image} -> ${new_img}" docker tag ${image} ${new_img}  docker push ${new_img} doneCopy the code

Docker images –format ‘{{.repository}}:{{.tag}}’

reference

  • www.runoob.com/linux/linux…
  • Blog. Zhenglin. Work/docker/save…
  • Linkscue.com/posts/2019-…