Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 944
Sitharthan Anbazhakan Avatar asked Dec 03 '18 12:12

Sitharthan Anbazhakan


People also ask

Can Docker run multiple processes?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

Can you have multiple froms in Dockerfile?

With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image.

How do I pull multiple images in Docker?

Pull a repository with multiple images By default, docker pull pulls a single image from the registry. A repository can contain multiple images. To pull all images from a repository, provide the -a (or --all-tags ) option when using docker pull .


2 Answers

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

like image 84
Chris Stryczynski Avatar answered Sep 18 '22 08:09

Chris Stryczynski


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
like image 23
ant Avatar answered Sep 20 '22 08:09

ant