'How to do "docker load" for multiple tar files
I have list of .tar docker image files , I have tried loading docker images using below commands
docker load -i *.tar
docker load -i alldockerimages.tar
where alldockerimages.tar
contains all individual tar files .
Let me know how we can load multiple tar files.
Solution 1:[1]
First I attempted to use the glob expression approach you first described:
# download some images to play with
docker pull alpine
docker pull nginx:alpine
# stream the images to disk as tarballs
docker save alpine > alpine.tar
docker save nginx:alpine > nginx.tar
# delete the images so we can attempt to load them from scratch
docker rmi alpine nginx:alpine
# issue the load command to try and load all images at once
cat *.tar | docker load
Unfortunately this only resulted in alpine.tar
being loaded. It was my (presumably faulty) understanding that the glob expression would be expanded and ultimately cause the docker load
command to be run for every file into which the glob expression expanded.
Therefore, one has to use a shell for
loop to load all tarballs sequentially:
for f in *.tar; do
cat $f | docker load
done
Solution 2:[2]
Using xargs:
ls -1 *.tar | xargs --no-run-if-empty -L 1 docker load -i
(A previous revision left off the -i flag to "docker load".)
Solution 3:[3]
Use the script described in save-load-docker-images.sh to save or load the images. For your case it would be
./save-load-docker-images.sh load -d <directory-location>
Solution 4:[4]
You can try the next option using find:
find -type f -name "*.tar" -exec docker load --input "{}" \;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ant |
Solution 2 | greybeard |
Solution 3 | Learner |
Solution 4 | Konstantin Albutov |