Save the docker load output to another file

Viewed 28

I have txt file ( input.txt) which contains names of tar file

adminsrv.tar
alertmanager.tar
alpine-bash.tar
alpine.tar
authsrv.tar

I want run the below command on input.txt and save the output of the command on output.txt:

sudo docker load -i adminsrv.tar
sudo docker load -i alertmanager.tar
....
....

I tried

input=/var/tmp/input.txt
sudo docker load -i $input | tee  /var/tmp/output.txt

and

input=/var/tmp/input.txt
sudo docker load -i $input >> /var/tmp/output.txt

but i am getting error :

Error processing tar file(exit status 1): archive/tar: invalid tar header.

How can i can the expected output which is

Loaded image: registry.xyz-edge.net/adminsrv:v1.2022.0-onprem

on a file

1 Answers

Try changing

sudo docker load -i $input | tee  /var/tmp/output.txt

into

(sudo docker load -i $input) | tee  /var/tmp/output.txt

So, you create an inner bash shell only for docker load, then its output will be captured by the pipe.

Let me know it works.

Related