Last active
July 31, 2023 09:18
-
-
Save daalvand/18c5a09fa844554f82bccc13d057ff82 to your computer and use it in GitHub Desktop.
Backup Docker Images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| images_dir="$(dirname "$(readlink -f "$0")")/images" | |
| mkdir -p $images_dir | |
| #This awk command removes duplicates based on the last field ({{.ID}}) of the input lines by utilizing an associative array seen. It prints only the first occurrence of each unique ID | |
| images=$(docker images --format "{{.Repository}}:{{.Tag}}-{{.ID}}" --filter "dangling=false" | awk -F'-' '!seen[$NF]++') | |
| for image in $images; do | |
| output_file="${image//[:\/]/_}.tar" | |
| image_name=${image%-*} | |
| echo $image_name | |
| docker save -o "${images_dir}/${output_file}" "${image_name}" | |
| done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| images_dir="$(dirname "$(readlink -f "$0")")/images" | |
| for F in "${image_dir}/*.tar"; do | |
| docker load < $F | |
| done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment