[英]Save multiple docker images using one command
目前我正在使用以下命令導出 docker 圖像
docker save imageName | gzip > imageName.tar.gz
docker save mysql | gzip > mysql.tar.gz
此命令適用於單個圖像,我的本地系統中有大量 docker 圖像,想要導出。 但我不知道如何導出docker images
可用的所有docker images
。
請指導我如何通過單個命令存檔。 這將分別保存當前目錄中的所有圖像ImageNames
docker save imageName1:tag1 imageName2:tag2 ... imageNameN:tagN | gzip > images.tar.gz
如果你需要獲取所有圖像,你可以使用這樣的東西(但它可能有點太多,所以要小心):
docker save $( \
docker images \
--format '{{.Repository}}:{{.Tag}}' \
--filter "dangling=false" \
| grep -v image_that_i_dont_want ) \
| gzip > images.tar.gz
編輯:
如果您需要將系統上的所有圖像保存在單獨的文件中:
for img in $( docker images --format '{{.Repository}}:{{.Tag}}' --filter "dangling=false" ) ; do
base=${img#*/}
docker save "$img" | gzip > "${base//:/__}".tar.gz
done
試試這個腳本,這兩個腳本會幫你保存和加載docker鏡像,如果你有太多的鏡像,我想這些腳本會對你有所幫助。 保存 docker 圖像的腳本是:
#!/bin/bash
#files will be saved in the dir 'Docker_images'
mkdir Docker_images
cd Docker_images
directory=`pwd`
c=0
#save the image names in 'list.txt'
doc= docker images | awk '{print $1}' > list.txt
printf "START \n"
input="$directory/list.txt"
#Check and create the image tar for the docker images
while IFS= read -r line
do
one=`echo $line | awk '{print $1}'`
two=`echo $line | awk '{print $1}' | cut -c 1-3`
if [ "$one" != "<none>" ]; then
c=$((c+1))
printf "\n $one \n $two \n"
docker save -o $two$c'.tar' $one
printf "Docker image number $c successfully converted: $two$c \n \n"
fi
done < "$input"
加載 docker 鏡像的腳本是:
#!/bin/bash
cd Docker_images/
directory=`pwd`
ls | grep tar > files.txt
c=0
printf "START \n"
input="$directory/files.txt"
while IFS= read -r line
do
c=$((c+1))
printf "$c) $line \n"
docker load -i $line
printf "$c) Successfully created the Docker image $line \n \n"
done < "$input"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.