16

I have list of .tar docker image files , I have tried loading docker images using below commands

  1. docker load -i *.tar
  2. docker load -i alldockerimages.tar

where alldockerimages.tar contains all individual tar files .

Let me know how we can load multiple tar files.

4 Answers 4

15

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".)

1
  • 3
    Add a -i to the end and this works. Also, sudo before docker if you need to run docker as root.
    – Magnetron
    Jun 9, 2020 at 13:44
9

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
1
  • 2
    I use this: mkdir -p myFolder && tar xvf BigFileWithManyImages.tar -C $_ && for f in $_/images/*.tar.gz; do docker load -i $f ; done1
    – Tilo
    Feb 6, 2019 at 18:45
1

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>
1

You can try the next option using find:

find -type f -name "*.tar" -exec docker load --input "{}" \;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.