Search code examples
dockerdocker-compose

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

  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.


Solution

  • 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